diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-11-25 10:16:54 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-11-25 10:16:54 +0100 |
commit | 1b1126bd023a2bb92699773a1867358067dabcb8 (patch) | |
tree | 6fd56d034e5a154c7992e7855d61691cecd043c4 /numlib/rand.h | |
parent | cb5c7cec4aa1946f75dc3d408eb7f1051f3fb3d4 (diff) | |
parent | f6b8e0eae4374f339487a33e3e4fe5462d5816e1 (diff) |
Update upstream source from tag 'upstream/2.0.0'
Update to upstream version '2.0.0'
with Debian dir e866e6e75661017faaa5331becda76021407390b
Diffstat (limited to 'numlib/rand.h')
-rwxr-xr-x[-rw-r--r--] | numlib/rand.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/numlib/rand.h b/numlib/rand.h index 46f79f2..e190fcd 100644..100755 --- 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 |