summaryrefslogtreecommitdiff
path: root/numlib/rand.h
diff options
context:
space:
mode:
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