Go to the first, previous, next, last section, table of contents.

Random number generator initialization

Random: gsl_rng * gsl_rng_alloc (const gsl_rng_type * T)
This function returns a pointer to a newly-created instance of a random number generator of type T. For example, the following code creates an instance of the Tausworthe generator,

gsl_rng * r = gsl_rng_alloc (gsl_rng_taus);

If there is insufficient memory to create the generator then the function returns a null pointer and the error handler is invoked with an error code of GSL_ENOMEM.

The generator is automatically initialized with the default seed, gsl_rng_default_seed. This is zero by default but can be changed either directly or by using the environment variable GSL_RNG_SEED (see section Random number environment variables).

The details of the available generator types are described later in this chapter.

Random: void gsl_rng_set (const gsl_rng * r, unsigned long int s)
This function initializes (or `seeds') the random number generator. If the generator is seeded with the same value of s on two different runs, the same stream of random numbers will be generated by successive calls to the routines below. If different values of s are supplied, then the generated streams of random numbers should be completely different. If the seed s is zero then the standard seed from the original implementation is used instead. For example, the original Fortran source code for the ranlux generator used a seed of 314159265, and so choosing s equal to zero reproduces this when using gsl_rng_ranlux.

Random: void gsl_rng_free (gsl_rng * r)
This function frees all the memory associated with the generator r.


Go to the first, previous, next, last section, table of contents.