diff --git a/src/rnd_generators.cpp b/src/rnd_generators.cpp index 545e236ec840583ddedd6c670e7a0a15cefe2511..1270a1666670691c0632c5c2b29c28cb3602b21d 100644 --- a/src/rnd_generators.cpp +++ b/src/rnd_generators.cpp @@ -27,6 +27,7 @@ float GetRandomGauss(const float mean, const float sigma, const bool reseed) { static gsl_rng *randState=NULL; + static unsigned long seed=-1; //do we need to init random generator? if (randState == NULL || reseed == true) @@ -34,9 +35,10 @@ float GetRandomGauss(const float mean, const float sigma, const bool reseed) //yes, we do: //create instance of the generator and seed it if (randState == NULL) randState = gsl_rng_alloc(gsl_rng_default); - unsigned long s=-1 * (int) time(NULL); - DEBUG_REPORT("GetRandomGauss(): randomness started with seed " << s); - gsl_rng_set(randState,s); + if (seed == -1) seed=-1 * (int) time(NULL); + else ++seed; + DEBUG_REPORT("GetRandomGauss(): randomness started with seed " << seed); + gsl_rng_set(randState,seed); } return ( (float)gsl_ran_gaussian(randState, sigma) + mean ); @@ -46,6 +48,7 @@ float GetRandomGauss(const float mean, const float sigma, const bool reseed) float GetRandomUniform(const float A, const float B, const bool reseed) { static gsl_rng *randState=NULL; + static unsigned long seed=-1; //do we need to init random generator? if (randState == NULL || reseed == true) @@ -53,9 +56,10 @@ float GetRandomUniform(const float A, const float B, const bool reseed) //yes, we do: //create instance of the generator and seed it if (randState == NULL) randState = gsl_rng_alloc(gsl_rng_default); - unsigned long s=-1 * (int) time(NULL); - DEBUG_REPORT("GetRandomUniform(): randomness started with seed " << s); - gsl_rng_set(randState,s); + if (seed == -1) seed=-1 * (int) time(NULL); + else ++seed; + DEBUG_REPORT("GetRandomUniform(): randomness started with seed " << seed); + gsl_rng_set(randState,seed); } return ( (float)gsl_ran_flat(randState, A,B) ); @@ -65,6 +69,7 @@ float GetRandomUniform(const float A, const float B, const bool reseed) unsigned int GetRandomPoisson(const float mean, const bool reseed) { static gsl_rng *randState=NULL; + static unsigned long seed=-1; //do we need to init random generator? if (randState == NULL || reseed == true) @@ -72,9 +77,10 @@ unsigned int GetRandomPoisson(const float mean, const bool reseed) //yes, we do: //create instance of the generator and seed it if (randState == NULL) randState = gsl_rng_alloc(gsl_rng_default); - unsigned long s=-1 * (int) time(NULL); - DEBUG_REPORT("GetRandomPoisson(): randomness started with seed " << s); - gsl_rng_set(randState,s); + if (seed == -1) seed=-1 * (int) time(NULL); + else ++seed; + DEBUG_REPORT("GetRandomPoisson(): randomness started with seed " << seed); + gsl_rng_set(randState,seed); } return ( gsl_ran_poisson(randState, mean) );