From a53faf45652d31d3f370884b37d21c86eae12115 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 6 Dec 2000 19:01:57 +0000 Subject: [PATCH] Updated random interface so we can optionally specify our own seed value. --- simgear/math/sg_random.c | 15 ++++++++++++--- simgear/math/sg_random.h | 6 +++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/simgear/math/sg_random.c b/simgear/math/sg_random.c index 654cf21c..dcabf119 100644 --- a/simgear/math/sg_random.c +++ b/simgear/math/sg_random.c @@ -49,9 +49,7 @@ // Seed the random number generater with time() so we don't see the // same sequence every time -void sg_srandom(void) { - // fgPrintf( FG_MATH, FG_INFO, "Seeding random number generater\n"); - +void sg_srandom_time(void) { #ifdef HAVE_RAND srand(time(NULL)); #else @@ -60,6 +58,17 @@ void sg_srandom(void) { } +// Seed the random number generater with your own seed so can set up +// repeatable randomization. +void sg_srandom( unsigned int seed ) { +#ifdef HAVE_RAND + srand( seed ); +#else + srandom( seed ); +#endif +} + + // return a random number between [0.0, 1.0) double sg_random(void) { #ifdef HAVE_RAND diff --git a/simgear/math/sg_random.h b/simgear/math/sg_random.h index 3c41071e..1ff1b1de 100644 --- a/simgear/math/sg_random.h +++ b/simgear/math/sg_random.h @@ -33,7 +33,11 @@ extern "C" { // Seed the random number generater with time() so we don't see the // same sequence every time -void sg_srandom(void); +void sg_srandom_time(void); + +// Seed the random number generater with your own seed so can set up +// repeatable randomization. +void sg_srandom( unsigned int seed ); // return a random number between [0.0, 1.0) double sg_random(void); -- 2.39.5