aboutsummaryrefslogtreecommitdiff
path: root/random/include
diff options
context:
space:
mode:
Diffstat (limited to 'random/include')
-rw-r--r--random/include/random/mt19937-64.h40
-rw-r--r--random/include/random/random.h3
2 files changed, 43 insertions, 0 deletions
diff --git a/random/include/random/mt19937-64.h b/random/include/random/mt19937-64.h
new file mode 100644
index 0000000..bd1125f
--- /dev/null
+++ b/random/include/random/mt19937-64.h
@@ -0,0 +1,40 @@
1#pragma once
2
3#include <stdint.h>
4
5#define MT19937_64_NN 312
6
7typedef struct mt19937_64 {
8 uint64_t mt[MT19937_64_NN]; // The array for the state vector.
9 int mti; // mti==NN+1 means mt[NN] is not initialized.
10} mt19937_64;
11
12/// Creates a default-initialized 64-bit Mersenne Twister PRNG.
13mt19937_64 mt19937_64_make();
14
15/// Initializes the PRNG with a seed.
16void mt19937_64_init(mt19937_64* rng, uint64_t seed);
17
18/// Initializes the PRNG with an array of values.
19/// |init_key| is the array for initializing keys.
20/// |key_length| is its length.
21void mt19937_64_init_by_array64(
22 mt19937_64* rng, uint64_t init_key[], uint64_t key_length);
23
24/// Generates a random number in the [0, 2^64-1]-interval.
25uint64_t mt19937_64_gen64u(mt19937_64* rng);
26
27/// Generates a random number in the [0, 2^63-1]-interval.
28int64_t mt19937_64_gen64i(mt19937_64* rng);
29
30/// Generates a random number in the [0,1]-real-interval.
31double mt19937_64_gen_real1(mt19937_64* rng);
32
33/// Generates a random number in the [0,1)-real-interval.
34double mt19937_64_gen_real2(mt19937_64* rng);
35
36/// Generates a random number in the (0,1)-real-interval.
37double mt19937_64_gen_real3(mt19937_64* rng);
38
39/// Generates a random number in the (-1,+1)-real-interval.
40double mt19937_64_gen_real4(mt19937_64* rng);
diff --git a/random/include/random/random.h b/random/include/random/random.h
new file mode 100644
index 0000000..5499f62
--- /dev/null
+++ b/random/include/random/random.h
@@ -0,0 +1,3 @@
1#pragma once
2
3#include <random/mt19937-64.h>