Monte Carlo in GSL

Joakim Hove
Wed Feb 18 13:27:00 GMT 2004

"Przemyslaw Sliwa" <> writes:

> Therefore I have to use the random number generator gsl_ran_gaussian
> (const gsl_rng * r, double sigma).

Well, gsl_ran_gaussian() returns random numbers sampled from the
gaussian distribution (with zero mean and) variance sigma^2 - by
*using* the random number generator r.

Maybe you should look into the "Sampling from a random number
generator" section in the manual.

> The question is: Do I have to execute the statement
>   gsl_rng_env_setup();
>   T = gsl_rng_default;
>   r = gsl_rng_alloc (T);
> each time I compute the value of my function or just once at the beginning
> of the process where I solve the equation.

This you will typically only do once at program startup.

> My problem is: I want that the random numbers I generate are purelly
> random 

Well - then you must go elsewere. A computer can only generate
pseudo-random numbers, however that is typically good enough!  See the
function gsl_rng_set() to seed the generator.

> and not that the series of the numbers repeats.

All random number generators have a period P, after which the
'random' sequence starts over again, if you read about the various
generators in the documentation you can see (estimates) of the period
for the different generators.

HTH - Joakim

 / Joakim Hove  /  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /

More information about the Gsl-discuss mailing list