spinn_common 7.2.2
Support code for SpiNNaker applications.
|
Pseudo-random number generators. More...
Go to the source code of this file.
Marsaglia 32-bit KISS uniform random number generator | |
Implementation of a Marsaglia 32-bit KISS generator which uses no multiply instructions 209.9 nanosecs (i.e. 42 ticks) per call Only available in simple form. Very good for single stream of PRNs. Cite: Marsaglia, George. (2011) RNGs with periods exceeding 10 (40million). Message-ID! | |
typedef uint32_t | mars_kiss64_seed_t[4] |
Seed type for the Marsaglia KISS 64 RNG. | |
uint32_t | mars_kiss32 (void) |
Marsaglia 32-bit KISS generator using no multiplication instructions. | |
uint32_t | mars_kiss64_simp (void) |
Implementation of Marsaglia JKISS RNG uses 64-bit value and 2x multiplies. | |
void | validate_mars_kiss64_seed (mars_kiss64_seed_t seed) |
Validate seed for Marsaglia KISS 64. | |
uint32_t | mars_kiss64_seed (mars_kiss64_seed_t seed) |
The Marsaglia KISS 64 RNG with custom seed. | |
WELL 1024a | |
WELL 1024a long cycle generator (21024 - 1) from L'Ecuyer & Panneton. Better equi-distribution and warm-up performance than Mersenne Twister, and faster. Cite: Panneton, François & L’Ecuyer, Pierre & Matsumoto, Makoto. (2006). Improved long-period generators based on linear recurrences modulo 2. ACM Trans. Math. Softw.. 32. 1-16. DOI: 10.1145/1132973.1132974. | |
typedef uint32_t | WELL1024a_seed_t[33] |
Seed type for the L'Ecuyer WELL 1024a RNG. | |
void | init_WELL1024a_simp (void) |
The initialiser function that MUST BE CALLED ONCE before WELLRNG1024a_simp() is used. Global WELL1024a seed is randomised each time it is called. | |
uint32_t | WELL1024a_simp (void) |
The WELL generator itself. | |
void | validate_WELL1024a_seed (WELL1024a_seed_t seed) |
MUST USE THIS before passing the seed to WELL1024a_seed() the first time. | |
uint32_t | WELL1024a_seed (WELL1024a_seed_t seed) |
The WELL 1024a RNG with custom seed. | |
Non-Uniform RNGs | |
Being added to all the time, and updated for better speed as fixed-point transcendentals and optimised multiplies become available | |
typedef uint32_t(* | uniform_rng) (uint32_t *) |
The interface type to the uniform RNGs. | |
s1615 | exponential_dist_variate (uniform_rng uni_rng, uint32_t *seed_arg) |
Von Neuman's exponential distribution generator. | |
s1615 | gaussian_dist_variate (uniform_rng uni_rng, uint32_t *seed_arg) |
Returns standard Gaussian deviate. | |
uint32_t | poisson_dist_variate (uniform_rng uni_rng, uint32_t *seed_arg, s1615 lambda) |
A poisson distributed random variable, given \( \exp(-\lambda) \). | |
uint32_t | poisson_dist_variate_exp_minus_lambda (uniform_rng uni_rng, uint32_t *seed_arg, u032 exp_minus_lambda) |
Use this version for Poisson with pre-calculated exp(-λ) for speed gain. | |
Pseudo-random number generators.
These all return well-distributed unsigned 32-bit ints that have been tested rigorously on the DIEHARD, dieharder and TestU01 test suites. The Marsaglia KISS generators are slightly faster and the 64-bit one uses the theoretically superior multiplicative algorithm. The WELL1024a has a cycle length of (2^1024)-1
Two versions are available. A simple version which has a global hidden seed which does not need to be set, and a custom version which allows seeds to be set by the user to either
across multiple random number streams.
These generators can all be used with the non-uniform RNGs below.
typedef uint32_t WELL1024a_seed_t[33] |
Seed type for the L'Ecuyer WELL 1024a RNG.
The 33rd element is the static variable used in simple version.
typedef uint32_t(* uniform_rng) (uint32_t *) |
The interface type to the uniform RNGs.
Interface to a generic uniform random number generator is defined as follows
This will generate some argument type warnings when used with simple URNGs but avoids a lot of code duplication and allows use of any Uniform RNG with any Non-Uniform variates which is valuable flexibility.
uint32_t mars_kiss32 | ( | void | ) |
Marsaglia 32-bit KISS generator using no multiplication instructions.
Only available in simple form. Very good for single stream of PRNs.
uint32_t mars_kiss64_simp | ( | void | ) |
Implementation of Marsaglia JKISS RNG uses 64-bit value and 2x multiplies.
The best general purpose trade-off between speed, equidistribution and cycle length.
void validate_mars_kiss64_seed | ( | mars_kiss64_seed_t | seed | ) |
Validate seed for Marsaglia KISS 64.
[in] | seed | The seed to validate |
uint32_t mars_kiss64_seed | ( | mars_kiss64_seed_t | seed | ) |
The Marsaglia KISS 64 RNG with custom seed.
[in] | seed | The RNG state, including seed value. |
uint32_t WELL1024a_simp | ( | void | ) |
The WELL generator itself.
void validate_WELL1024a_seed | ( | WELL1024a_seed_t | seed | ) |
MUST USE THIS before passing the seed to WELL1024a_seed() the first time.
[in] | seed | The seed to validate |
uint32_t WELL1024a_seed | ( | WELL1024a_seed_t | seed | ) |
The WELL 1024a RNG with custom seed.
[in] | seed | The RNG state, including seed value. |
s1615 exponential_dist_variate | ( | uniform_rng | uni_rng, |
uint32_t * | seed_arg | ||
) |
Von Neuman's exponential distribution generator.
from Ripley p.230 and adapted for our types
Mean number of U(0,1) per call = 5.2
[in] | uni_rng | The uniform random number generator |
[in] | seed_arg | The seed argument to the uniform RNG. |
s1615 gaussian_dist_variate | ( | uniform_rng | uni_rng, |
uint32_t * | seed_arg | ||
) |
Returns standard Gaussian deviate.
translation of NR in C version of Box-Muller
[in] | uni_rng | The uniform random number generator |
[in] | seed_arg | The seed argument to the uniform RNG. |
uint32_t poisson_dist_variate | ( | uniform_rng | uni_rng, |
uint32_t * | seed_arg, | ||
s1615 | lambda | ||
) |
A poisson distributed random variable, given \( \exp(-\lambda) \).
This is Knuth's method, and is \( O(n) \), so don't use for large \( \lambda \)
[in] | uni_rng | The uniform random number generator |
[in] | seed_arg | The seed argument to the uniform RNG. |
[in] | lambda | The shape parameter of the distribution, \( \lambda \) |
uint32_t poisson_dist_variate_exp_minus_lambda | ( | uniform_rng | uni_rng, |
uint32_t * | seed_arg, | ||
u032 | exp_minus_lambda | ||
) |
Use this version for Poisson with pre-calculated exp(-λ) for speed gain.
[in] | uni_rng | The uniform random number generator |
[in] | seed_arg | The seed argument to the uniform RNG. |
[in] | exp_minus_lambda | The shape parameter of the distribution, \( \exp(-\lambda) \). |
while (p > exp_minus_lambda) { p *= ulrbits(uni_rng(seed_arg)); k++; } return k;