Function PGARandom01
Defined in File random.c
Function Documentation
-
double PGARandom01(PGAContext *ctx, int newseed)
Generate a uniform random number on the interval [0,1).
Description
If the second argument is 0 it returns the next random number in the sequence. Otherwise, the second argument is used as a new seed for the population.
This is a C language implementation of the universal random number generator proposed by George Marsaglia, Arif Zaman, and Wai Wan Tsang [MZT90] and translated from F. James’ version [Jam90].
This algorithm is a combination of a lagged Fibonacci and arithmetic sequence (F. James) generator with period of \(2^{144}\). It provides 32-bit floating point numbers in the range from zero to one. It is claimed to be portable and provides bit-identical results on all machines with at least 24-bit mantissas.
PGARandom01()
should be initialized with a 32-bit integer seed such that \(0 \le seed \le 900,000,000\). Each of these 900,000,000 values gives rise to an independent sequence of \(\approx 10^{30}\).Example
To get the next random number use
PGAContext *ctx; double r; ... r = PGARandom01 (ctx, 0);
- Parameters:
ctx – context variable
newseed – either 0 to get the next random number, or nonzero to reseed
- Returns:
A random number on the interval [0,1)