summaryrefslogtreecommitdiff
path: root/numlib/rand.h
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-12-03 20:38:41 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-12-03 20:38:41 +0100
commitba627dd9ecb578e9852c7b9cce67ec63199d1acf (patch)
tree27c4258311ca8c8ed7ff67a8a0bc7280e8fcae79 /numlib/rand.h
parent69aec3b712232e93600ecd741269fed1f90b412a (diff)
parent3abb40d43649adb3807180692d8579c405524675 (diff)
Merge branch 'release/2.0.0+repack-1'2.0.0+repack-1
Diffstat (limited to 'numlib/rand.h')
-rwxr-xr-x[-rw-r--r--]numlib/rand.h40
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