Browse code

Add theft

John Hawthorn authored on 03/04/2017 09:11:20
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,36 @@
1
+#ifndef THEFT_MT_H
2
+#define THEFT_MT_H
3
+
4
+#include <stdint.h>
5
+
6
+/* Wrapper for Mersenne Twister.
7
+ * See copyright and license in theft_mt.c, more details at:
8
+ *     http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
9
+ *
10
+ * The code has been modified to store internal state in heap/stack
11
+ * allocated memory, rather than statically allocated memory, to allow
12
+ * multiple instances running in the same address space. */
13
+
14
+#define THEFT_MT_PARAM_N 312
15
+
16
+struct theft_mt {
17
+    uint64_t mt[THEFT_MT_PARAM_N]; /* the array for the state vector  */
18
+    int16_t mti;
19
+};
20
+
21
+/* Heap-allocate a mersenne twister struct. */
22
+struct theft_mt *theft_mt_init(uint64_t seed);
23
+
24
+/* Free a heap-allocated mersenne twister struct. */
25
+void theft_mt_free(struct theft_mt *mt);
26
+
27
+/* Reset a mersenne twister struct, possibly stack-allocated. */
28
+void theft_mt_reset(struct theft_mt *mt, uint64_t seed);
29
+
30
+/* Get a 64-bit random number. */
31
+uint64_t theft_mt_random(struct theft_mt *mt);
32
+
33
+/* Generate a random number on [0,1]-real-interval. */
34
+double theft_mt_random_double(struct theft_mt *mt);
35
+
36
+#endif