GSL Uniform Random Number Generator

Posted by Jamaia on Programmers See other posts from Programmers or by Jamaia
Published on 2012-03-18T18:57:02Z Indexed on 2012/03/19 10:16 UTC
Read the original article Hit count: 294

Filed under:

I want to use GSL's uniform random number generator. On their website, they include this sample code:

 #include <stdio.h>
 #include <gsl/gsl_rng.h>

 int
 main (void)
 {
   const gsl_rng_type * T;
   gsl_rng * r;

   int i, n = 10;

   gsl_rng_env_setup();

   T = gsl_rng_default;
   r = gsl_rng_alloc (T);

   for (i = 0; i < n; i++) 
     {
       double u = gsl_rng_uniform (r);
       printf ("%.5f\n", u);
     }

   gsl_rng_free (r);

   return 0;
 }

However, this does not rely on any seed and so, the same random numbers will be produced each time.

They also specify the following:

The generator itself can be changed using the environment variable GSL_RNG_TYPE. Here is the output of the program using a seed value of 123 and the multiple-recursive generator mrg,

 $ GSL_RNG_SEED=123 GSL_RNG_TYPE=mrg ./a.out

But I don't understand how to implement this. Any ideas as to what modifications I can make to the above code to incorporate the seed?

© Programmers or respective owner