X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d5b93304c003059f0994a809fb147eb7e90791c6..c19150f4a1c712b3435ccc04b30e7cfacd66c689:/src/surf/random_mgr.c diff --git a/src/surf/random_mgr.c b/src/surf/random_mgr.c index bbbe414581..44f8534eab 100644 --- a/src/surf/random_mgr.c +++ b/src/surf/random_mgr.c @@ -10,18 +10,19 @@ static double drand48(void) } #endif -static double custom_random(int generator){ +static double custom_random(Generator generator, long int *seed){ switch(generator) { - - case DRAND48:return drand48(); - case RAND: return (double)rand()/RAND_MAX; + case DRAND48: + return drand48(); + case RAND: + return (double)rand_r((unsigned int*)seed)/RAND_MAX; default: return drand48(); } } /* Generate numbers between min and max with a given mean and standard deviation */ -float random_generate(random_data_t random){ - float x1, x2, w, y; +double random_generate(random_data_t random){ + double x1, x2, w, y; if (random == NULL) return 0.0f; @@ -31,8 +32,8 @@ float random_generate(random_data_t random){ y1 = sqrt( - 2 * log(x1) ) * cos( 2 * pi * x2 ) */ do { - x1 = 2.0 * custom_random(random->generator) - 1.0; - x2 = 2.0 * custom_random(random->generator) - 1.0; + x1 = 2.0 * custom_random(random->generator,&(random->seed)) - 1.0; + x2 = 2.0 * custom_random(random->generator,&(random->seed)) - 1.0; w = x1 * x1 + x2 * x2; } while ( w >= 1.0 ); @@ -46,9 +47,12 @@ float random_generate(random_data_t random){ return y; } -random_data_t random_new(int generator, int min, int max, int mean, int stdDeviation){ +random_data_t random_new(Generator generator, long int seed, + double min, double max, double mean, + double stdDeviation){ random_data_t random = xbt_new0(s_random_data_t, 1); random->generator = generator; + random->seed = seed; random->min = min; random->max = max; random->mean = mean;