SPRAAK
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Typedefs | Functions | Variables
random.c File Reference

Generating peudo random numbers. More...

Typedefs

typedef struct SprRandGen SprRandGen
 

Functions

void spr_rand_init (SprRandGen *restrict rg_state, const uint32_t *val, int Nval)
 
uint32_t spr_rand_u32 (SprRandGen *restrict rg_state)
 
uint64_t spr_rand_u64 (SprRandGen *restrict rg_state)
 
float spr_rand_f32 (SprRandGen *restrict rg_state)
 
double spr_rand_f64q (SprRandGen *restrict rg_state)
 Calculate the next 32 (pseudo) random bits and update the state of the random generator rg_state. More...
 
double spr_rand_f64 (SprRandGen *restrict rg_state)
 
double spr_randn_f64 (SprRandGen *restrict rg_state)
 
unsigned int spr_rand_modN (unsigned int n, SprRandGen *restrict rg_state)
 
float * spr_rand_vec_f32 (float x[], int n, float rmax, SprRandGen *restrict rg_state)
 
float * spr_randn_vec_f32 (float x[], int n, SprRandGen *restrict rg_state)
 
int spr_rand_m (int indx[], int n, int m, SprRandGen *restrict rg_state)
 

Variables

SprRandGen spr_rand_default
 

Detailed Description

Generating peudo random numbers.

Author
Kris Demuynck
Date
31 May 2010

Generate pseudo random number. Multiple generators can be generated. The global generator is MT-safe in the sense that it will not crash and will provide randon numbers. However, even after reorganizing the random numbers, the sequence may still differ from those returned in an equivalent single threaded application.

Algorithm:
François Panneton, Pierre L'Ecuyer, Makoto Matsumoto Improved long-period generators based on linear recurrences modulo 2, ACM Transactions on Mathematical Software (TOMS), Volume 32, Issue 1, pages 1–16, March 2006
Revision History:
16 Nov 1991 - DVC
First version, based on rand()
6 Jan 1995 - KD
Use rand48() functions for better distributed random variables.
28 Oct 2002 - KD
Added a random generator for normal distributed numbers.
24 Nov 2008 - JR
Mersenne Twister random generator (single static random generator, non MT-safe)
31 May 2010 - KD
Use of the WELL1024a random generator