| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
17.6 Random number environment variables
The library allows you to choose a default generator and seed from the
environment variables GSL_RNG_TYPE and GSL_RNG_SEED and
the function gsl_rng_env_setup. This makes it easy try out
different generators and seeds without having to recompile your program.
- Function: const gsl_rng_type * gsl_rng_env_setup (void)
This function reads the environment variables
GSL_RNG_TYPEandGSL_RNG_SEEDand uses their values to set the corresponding library variablesgsl_rng_defaultandgsl_rng_default_seed. These global variables are defined as follows,extern const gsl_rng_type *gsl_rng_default extern unsigned long int gsl_rng_default_seed
The environment variable
GSL_RNG_TYPEshould be the name of a generator, such astausormt19937. The environment variableGSL_RNG_SEEDshould contain the desired seed value. It is converted to anunsigned long intusing the C library functionstrtoul.If you don't specify a generator for
GSL_RNG_TYPEthengsl_rng_mt19937is used as the default. The initial value ofgsl_rng_default_seedis zero.
Here is a short program which shows how to create a global
generator using the environment variables GSL_RNG_TYPE and
GSL_RNG_SEED,
|
Running the program without any environment variables uses the initial
defaults, an mt19937 generator with a seed of 0,
$ ./a.outgenerator type: mt19937 seed = 0 first value = 4293858116 |
By setting the two variables on the command line we can change the default generator and the seed,
$ GSL_RNG_TYPE="taus" GSL_RNG_SEED=123 ./a.out GSL_RNG_TYPE=taus GSL_RNG_SEED=123 generator type: taus seed = 123 first value = 2720986350 |
