spinn_common 7.2.2
Support code for SpiNNaker applications.
|
pseudo-random number generators More...
Macros | |
#define | R 32 |
Size of the global WELL1024a state vector. | |
Functions | |
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 STATE) |
The WELL 1024a RNG with custom seed. | |
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. | |
uint32_t | mars_kiss64_seed (mars_kiss64_seed_t seed) |
The Marsaglia KISS 64 RNG with custom seed. | |
void | validate_mars_kiss64_seed (mars_kiss64_seed_t seed) |
Validate seed for Marsaglia KISS 64. | |
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. | |
Variables | |
static uint32_t | STATE [R] |
The global state vector for WELL1024a_simp() | |
pseudo-random number generators
For all of these, to get a high resolution fixed-point number in (0,1) that uses the entire generator space use ulrbits() around return value to give a 32-bit unsigned long fract
Also other options to get a 16-bit unsigned fract by taking 16 MSBs of result and urbits()
If floating point is available then multiply by 2.32830643653869628906e-10
spin1_rand()
takes 134.9 nanosecs (i.e. 27 ticks) per call
WELL 1024a long cycle generator (2^1024 - 1) from L'Ecuyer & Panneton
Better equi-distribution and warm-up performance than Mersenne Twister, and faster
294.9 nanosecs (i.e. 59 ticks) per call
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. |
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.
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. |
void validate_mars_kiss64_seed | ( | mars_kiss64_seed_t | seed | ) |
Validate seed for Marsaglia KISS 64.
[in] | seed | The seed to validate |
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;