From f6b8e0eae4374f339487a33e3e4fe5462d5816e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 25 Nov 2017 10:16:00 +0100 Subject: New upstream version 2.0.0 --- numlib/rand.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) mode change 100644 => 100755 numlib/rand.h (limited to 'numlib/rand.h') diff --git a/numlib/rand.h b/numlib/rand.h old mode 100644 new mode 100755 index 46f79f2..e190fcd --- a/numlib/rand.h +++ b/numlib/rand.h @@ -13,6 +13,9 @@ extern "C" { #endif +/* - - - - - - - - - - - - - - - */ +/* Global state random generator */ + /* Return a random number between 0 and 4294967294 */ unsigned int rand32( /* Return 32 bit random number */ @@ -29,6 +32,43 @@ double d_rand(double min, double max); /* and an average deviation of 0.564 */ double norm_rand(void); +/* - - - - - - - - - - - - - - - */ +/* Explicit state random generator */ +/* Use NULL for global state */ + +#define RAND_TSIZE 2843 /* Prime */ +#define RAND_SEED 0x12345678 /* Default seed */ + +/* Should set to 0 to default intialize */ +typedef struct { + int pvs_inited; + unsigned int ran, last; + unsigned int pvs[RAND_TSIZE]; + + /* normal distribution 2nd value */ + int r2; /* 2nd value available */ + double nr2; /* 2nd value */ +} rand_state; + +/* Init rand_state to default */ +void rand_init(rand_state *p); + +/* Return a random number between 0 and 4294967294 */ +unsigned int +rand32_th(rand_state *p, +unsigned int seed); /* Optional seed. Non-zero re-initialized with that seed */ + +/* Return a random integer in the range min to max inclusive */ +int i_rand_th(rand_state *p, int min, int max); + +/* Return a random double in the range min to max inclusive */ +double d_rand_th(rand_state *p, double min, double max); + +/* Return a random floating point number with a gausian/normal */ +/* distribution, centered about 0.0, with standard deviation 1.0 */ +/* and an average deviation of 0.564 */ +double norm_rand_th(rand_state *p); + #ifdef __cplusplus } #endif -- cgit v1.2.3