1
0
Fork 0

Moved random routines from Utils/ to Math/

This commit is contained in:
curt 1997-07-30 16:04:08 +00:00
parent 34e2bac4d0
commit 233ffb3b10
3 changed files with 127 additions and 1 deletions

View file

@ -26,7 +26,7 @@
TARGET = libMath.a 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) OFILES = $(CFILES:.c=.o)
@ -68,12 +68,18 @@ MAT3mat.o:
MAT3vec.o: MAT3vec.o:
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
fg_random.o:
$(CC) $(CFLAGS) -c fg_random.c -o $@
polar.o: polar.o:
$(CC) $(CFLAGS) -c polar.c -o $@ $(CC) $(CFLAGS) -c polar.c -o $@
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $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 # Revision 1.10 1997/07/20 02:19:11 curt
# First stab at a system to generate os2 makefiles automatically. # First stab at a system to generate os2 makefiles automatically.
# #

68
Math/fg_random.c Normal file
View file

@ -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 <stdlib.h> /* for random(), srandom() */
#include <time.h> /* 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.
*
*/

52
Math/fg_random.h Normal file
View file

@ -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.
*
*/