From 233ffb3b10d9dfcbd01dedcfbfc13382beccff7a Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 30 Jul 1997 16:04:08 +0000 Subject: [PATCH] Moved random routines from Utils/ to Math/ --- Math/Makefile | 8 +++++- Math/fg_random.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ Math/fg_random.h | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Math/fg_random.c create mode 100644 Math/fg_random.h diff --git a/Math/Makefile b/Math/Makefile index 4e81cb4a..1eb41076 100644 --- a/Math/Makefile +++ b/Math/Makefile @@ -26,7 +26,7 @@ TARGET = libMath.a -CFILES = MAT3geom.c MAT3inv.c MAT3mat.c MAT3vec.c polar.c +CFILES = MAT3geom.c MAT3inv.c MAT3mat.c MAT3vec.c fg_random.c polar.c OFILES = $(CFILES:.c=.o) @@ -68,12 +68,18 @@ MAT3mat.o: MAT3vec.o: $(CC) $(CFLAGS) -c $< -o $@ +fg_random.o: + $(CC) $(CFLAGS) -c fg_random.c -o $@ + polar.o: $(CC) $(CFLAGS) -c polar.c -o $@ #--------------------------------------------------------------------------- # $Log$ +# Revision 1.11 1997/07/30 16:04:08 curt +# Moved random routines from Utils/ to Math/ +# # Revision 1.10 1997/07/20 02:19:11 curt # First stab at a system to generate os2 makefiles automatically. # diff --git a/Math/fg_random.c b/Math/fg_random.c new file mode 100644 index 00000000..5c212a72 --- /dev/null +++ b/Math/fg_random.c @@ -0,0 +1,68 @@ +/************************************************************************** + * fg_random.c -- routines to handle random number generation + * + * Written by Curtis Olson, started July 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#include /* for random(), srandom() */ +#include /* for time() to seed srandom() */ + +#include "fg_random.h" + +#ifndef USE_RAND +# ifdef sgi +# undef RAND_MAX +# define RAND_MAX 2147483647 +# endif +#endif + + +/* Seed the random number generater with time() so we don't see the + * same sequence every time */ +void fg_srandom(void) { +#ifdef USE_RAND + srand(time(NULL)); +#else + srandom(time(NULL)); +#endif +} + + +/* return a random number between [0.0, 1.0) */ +double fg_random(void) { +#ifdef USE_RAND + return(rand() / (double)RAND_MAX); +#else + return(random() / (double)RAND_MAX); +#endif +} + + +/* $Log$ +/* Revision 1.1 1997/07/30 16:04:09 curt +/* Moved random routines from Utils/ to Math/ +/* + * Revision 1.1 1997/07/19 22:31:57 curt + * Initial revision. + * + */ diff --git a/Math/fg_random.h b/Math/fg_random.h new file mode 100644 index 00000000..68a19afd --- /dev/null +++ b/Math/fg_random.h @@ -0,0 +1,52 @@ +/************************************************************************** + * fg_random.h -- routines to handle random number generation + * + * Written by Curtis Olson, started July 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#ifndef FG_RANDOM_H +#define FG_RANDOM_H + + +/* Seed the random number generater with time() so we don't see the + * same sequence every time */ +void fg_srandom(void); + +/* return a random number between [0.0, 1.0) */ +double fg_random(void); + + +#endif /* FG_RANDOM_H */ + + +/* $Log$ +/* Revision 1.1 1997/07/30 16:04:09 curt +/* Moved random routines from Utils/ to Math/ +/* + * Revision 1.2 1997/07/23 21:52:28 curt + * Put comments around the text after an #endif for increased portability. + * + * Revision 1.1 1997/07/19 22:31:57 curt + * Initial revision. + * + */ -- 2.39.2