spinn_common 7.3.1
Support code for SpiNNaker applications.
Loading...
Searching...
No Matches
Macros | Functions | Variables
random.c File Reference

pseudo-random number generators More...

#include "random.h"
#include "normal.h"
#include "stdfix-full-iso.h"
#include "stdfix-exp.h"

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()
 

Detailed Description

pseudo-random number generators

Author
Michael Hopkins
Date
February 2014

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

Function Documentation

◆ WELL1024a_simp()

uint32_t WELL1024a_simp ( void  )

The WELL generator itself.

Returns
A uniformly randomly distributed 32-bit value.

◆ validate_WELL1024a_seed()

void validate_WELL1024a_seed ( WELL1024a_seed_t  seed)

MUST USE THIS before passing the seed to WELL1024a_seed() the first time.

Parameters
[in]seedThe seed to validate

◆ WELL1024a_seed()

uint32_t WELL1024a_seed ( WELL1024a_seed_t  seed)

The WELL 1024a RNG with custom seed.

Parameters
[in]seedThe RNG state, including seed value.
Returns
A uniformly randomly distributed 32-bit value.

◆ mars_kiss32()

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.

Returns
A pseudo-random unsigned 32-bit integer.

◆ mars_kiss64_simp()

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.

Returns
A normally distributed 32-bit unsigned integer.

◆ mars_kiss64_seed()

uint32_t mars_kiss64_seed ( mars_kiss64_seed_t  seed)

The Marsaglia KISS 64 RNG with custom seed.

Parameters
[in]seedThe RNG state, including seed value.
Returns
A uniformly randomly distributed 32-bit value.

◆ validate_mars_kiss64_seed()

void validate_mars_kiss64_seed ( mars_kiss64_seed_t  seed)

Validate seed for Marsaglia KISS 64.

Note
MUST USE THIS before passing the seed to mars_kiss64_seed() the first time.
Parameters
[in]seedThe seed to validate

◆ exponential_dist_variate()

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
Parameters
[in]uni_rngThe uniform random number generator
[in]seed_argThe seed argument to the uniform RNG.
Returns
Exponentially distributed random number.

◆ gaussian_dist_variate()

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

Parameters
[in]uni_rngThe uniform random number generator
[in]seed_argThe seed argument to the uniform RNG.
Returns
Gaussian-distributed random number.

◆ poisson_dist_variate()

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 \)

Parameters
[in]uni_rngThe uniform random number generator
[in]seed_argThe seed argument to the uniform RNG.
[in]lambdaThe shape parameter of the distribution, \( \lambda \)
Returns
Poisson-distributed random number.
Remarks
DRL thinks the cast (from s16.15 to u0.32) might be wasteful.

◆ poisson_dist_variate_exp_minus_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.

Parameters
[in]uni_rngThe uniform random number generator
[in]seed_argThe seed argument to the uniform RNG.
[in]exp_minus_lambdaThe shape parameter of the distribution, \( \exp(-\lambda) \).
Returns
Poisson-distributed random number.
Remarks
DRL thinks this can be simplified to the following code:
while (p > exp_minus_lambda) {
    p *= ulrbits(uni_rng(seed_arg));
    k++;
}

return k;