GSL-RNG¶
This module introduce the class <gsl-rng> that provides a
uniform interface to a large collection of random number generators.
To create a random number generator with the BSD $gsl-rng-rand
generator and a seed:
let rng = make(<gsl-rng>, type: $gsl-rng-rand, seed: 1234);
format-out("generator type: %s\n", rng.gsl-rng-name);
format-out("seed = %d\n", rng.gsl-rng-seed);
format-out("first value = %d\n", rng.gsl-rng-get);
Random number environment variables¶
- gsl-rng-env-setup Function¶
This function reads the environment variables
GSL_RNG_TYPEandGSL_RNG_SEEDand uses their values to set the corresponding library variables gsl_rng_default and gsl_rng_default_seed.If you don’t specify a generator for
GSL_RNG_TYPEthen$gsl-rng-mt19937is used as the default. The initial value ofgsl-rng-default-seedis zero.- Signature:
gsl-rng-env-setup () => ()
- See also:
https://www.gnu.org/software/gsl/doc/html/rng.html#c.gsl_rng_env_setup
- Example:
Here we create a default random number generator with default seed:
gsl-rng-env-setup(); let rng = make(<gsl-rng>); format-out("generator type: %s\n", rng.gsl-rng-name); format-out("seed = %d\n", rng.gsl-rng-seed); format-out("first value = %d\n", rng.gsl-rng-get);
- Example:
Running the program without any environment variables,
$ test-rng.exe generator type: mt19937 seed = 0 first value = 4293858116
- Example:
We can pass the environment variables to choose type of algorithm and seed:
$ GSL_RNG_TYPE="taus" GSL_RNG_SEED=123 test-rng.exe GSL_RNG_TYPE=taus GSL_RNG_SEED=123 generator type: taus seed = 123 first value = 2720986350
Random generator base class¶
- <gsl-rng> Class¶
The class for random number generators.
- Superclasses:
<object>- Init-Keywords:
type – Type of random number generator. An instance of
<integer>. If no type is provided, it defaults to the environment variableGLS_RNG_TYPE.seed –
An instance of
<integer>that will be used as the seed for the random number generator. If no seed is provided it defaults to theGLS_RNG_SEEDenvironment variable or 0, if the variable is absent.- example:
let r1 = make(<gsl-rng>, type: $gsl-rng-cmrg, seed: 123456); let r2 = make(<gsl-rng>, seed: 123456); let r3 = make(<gsl-rng>);
Sampling¶
- gsl-rng-get Function¶
Returns a random number between the minimum and maximum value of the random number generator.
- gsl-rng-uniform Function¶
Returns a random floating point number uniformly distributed in the range [0,1).
- gsl-rng-uniform-positive Function¶
Returns a positive random number uniformly distributed in the range (0,1), excluding both 0.0 and 1.0. The number is obtained by sampling the generator with the algorithm of
gsl-rng-uniformuntil a non-zero value is obtained.
- gsl-rng-uniform-integer Function¶
Returns a random number between 0 and n-1 of the random number generator.
- Signature:
gsl-rng-uniform-integer (rng, n) => (number)
- Parameters:
- Values number:
A random number between 0 and n-1 of the random number generator as an instance of
<integer>.- Example:
let r = make(<gsl-rng>); let s = gsl-rng-uniform-integer(r, 10);
Auxiliary functions¶
- gsl-rng-name Function¶
Returns the name of the random number generator.
- Signature:
gsl-rng-name (rng) => (name)
- Parameters:
rng – An instance of
<gsl-rng>.
- Values name:
The name of the random number generator as an instance of
<string>.- Example:
let r = make(<gsl-rng>, type: $gsl-rng-rand); format-out("%s", r.gsl-rng-name); // rand
- gsl-rng-seed(<gsl-rng>) Method¶
Returns the seed of the random number generator
- gsl-rng-min Function¶
Returns the smallest value returned by the random number generator.
Random number generator algorithms¶
Below are all the algorithms of random number generators available,
whose constants can be passed in the class <gsl-rng>
construction with the type: keyword.
MT19937 generators¶
- $mt19937 Constant¶
- $mt19937-1999 Constant¶
- $mt19937-1998 Constant¶
RANLUX generators¶
- $ranlxs0 Constant¶
- $ranlxs1 Constant¶
- $ranlxs2 Constant¶
- $ranlxd1 Constant¶
- $ranlxd2 Constant¶
- $ranlux Constant¶
- $ranlux389 Constant¶
L’Ecuyer generators¶
- $cmrg Constant¶
- $mrg Constant¶
- $taus Constant¶
- $taus2 Constant¶
- $taus113 Constant¶
GSFR4¶
- $gfsr4 Constant¶
Unix random number generators¶
BSD generators¶
- $rand Constant¶
- $random-bsd Constant¶
- $random-glibc2 Constant¶
- $random-libc5 Constant¶
- $random8-bsd Constant¶
- $random8-glibc2 Constant¶
- $random8-libc5 Constant¶
- $random32-bsd Constant¶
- $random32-glibc2 Constant¶
- $random32-libc5 Constant¶
- $random64-bsd Constant¶
- $random64-glibc2 Constant¶
- $random64-libc5 Constant¶
- $random128-bsd Constant¶
- $random128-glibc2 Constant¶
- $random128-libc5 Constant¶
- $random256-bsd Constant¶
- $random256-glibc2 Constant¶
- $random256-libc5 Constant¶
- $rand48 Constant¶
- $ran0 Constant¶
- $ran1 Constant¶
- $ran2 Constant¶
- $ran3 Constant¶
Other random number generators¶
- $ranf Constant¶
- $ranmar Constant¶
- $r250 Constant¶
- $tt800 Constant¶
- $vax Constant¶
- $transputer Constant¶
- $randu Constant¶
- $minstd Constant¶
- $uni Constant¶
- $uni32 Constant¶
- $slatec Constant¶
- $zuf Constant¶
- $knuthran2 Constant¶
- $knuthran2002 Constant¶
- $knuthran Constant¶
- $borosh13 Constant¶
- $fishman18 Constant¶
- $fishman20 Constant¶
- $lecuyer21 Constant¶
- $waterman14 Constant¶
- $fishman2x Constant¶
- $coveyou Constant¶