Commit 2c8fc8f4 authored by Vladimír Ulman's avatar Vladimír Ulman
Browse files

Random generators now have their seeds dependent both on time and process ID.

(used to be depending only on time which produces exactly the same sequences
when executed at the very same time, e.g., from a script)

M    rnd_generators.cpp
parent f1356dd5
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <time.h>
#include <unistd.h>

#include "rnd_generators.h"
#include "../macros.h"
@@ -31,7 +32,7 @@ float GetRandomGauss(const float mean, const float sigma) {
		//yes, we do:
		//create instance of the generator and seed it
		randState = gsl_rng_alloc(gsl_rng_default);
		unsigned long s=-1 * (int) time(NULL);
		unsigned long s=-1 * (int)time(NULL) * (int)getpid();
		REPORT("randomness started with seed " << s);
		gsl_rng_set(randState,s);
	}
@@ -48,7 +49,7 @@ float GetRandomUniform(const float A, const float B) {
		//yes, we do:
		//create instance of the generator and seed it
		randState = gsl_rng_alloc(gsl_rng_default);
		unsigned long s=-1 * (int) time(NULL);
		unsigned long s=-1 * (int)time(NULL) * (int)getpid();
		REPORT("randomness started with seed " << s);
		gsl_rng_set(randState,s);
	}
@@ -65,7 +66,7 @@ unsigned int GetRandomPoisson(const float mean) {
		//yes, we do:
		//create instance of the generator and seed it
		randState = gsl_rng_alloc(gsl_rng_default);
		unsigned long s=-1 * (int) time(NULL);
		unsigned long s=-1 * (int)time(NULL) * (int)getpid();
		REPORT("randomness started with seed " << s);
		gsl_rng_set(randState,s);
	}