forked from cslarsen/mersenne-twister
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mersenne-twister.h
106 lines (89 loc) · 2.21 KB
/
mersenne-twister.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* The Mersenne Twister pseudo-random number generator (PRNG)
*
* This is an implementation of fast PRNG called MT19937,
* meaning it has a period of 2^19937-1, which is a Mersenne
* prime.
*
* This PRNG is fast and suitable for non-cryptographic code.
* For instance, it would be perfect for Monte Carlo simulations,
* etc.
*
* This code has been designed as a drop-in replacement for libc rand and
* srand(). If you need to mix them, you should encapsulate this code in a
* namespace.
*
* Written by Christian Stigen Larsen
* http://csl.name
*
* Distributed under the modified BSD license.
*
* 2015-02-17
*/
#ifndef MERSENNE_TWISTER_H
#define MERSENNE_TWISTER_H
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Maximum number you can get from rand().
*/
#define RAND_MAX INT32_MAX
/*
* Initialize the number generator with given seed.
* (LIBC REPLACEMENT FUNCTION)
*/
void srand(unsigned seed_value);
/*
* Extract a pseudo-random integer in the range 0 ... RAND_MAX.
* (LIBC REPLACEMENT FUNCTION)
*/
int rand();
/*
* Extract a pseudo-random unsigned 32-bit integer in the range 0 ... UINT32_MAX
*/
uint32_t rand_u32();
/*
* Combine two unsigned 32-bit pseudo-random numbers into one 64-bit
*/
uint64_t rand_u64();
/*
* Initialize Mersenne Twister with given seed value.
*/
void seed(uint32_t seed_value);
/*
* Return a random float in the CLOSED range [0, 1]
* Mnemonic: randf_co = random float 0=closed 1=closed
*/
float randf_cc();
/*
* Return a random float in the OPEN range [0, 1>
* Mnemonic: randf_co = random float 0=closed 1=open
*/
float randf_co();
/*
* Return a random float in the OPEN range <0, 1>
* Mnemonic: randf_oo = random float 0=open 1=open
*/
float randf_oo();
/*
* Return a random double in the CLOSED range [0, 1]
* Mnemonic: randd_co = random double 0=closed 1=closed
*/
double randd_cc();
/*
* Return a random double in the OPEN range [0, 1>
* Mnemonic: randd_co = random double 0=closed 1=open
*/
double randd_co();
/*
* Return a random double in the OPEN range <0, 1>
* Mnemonic: randd_oo = random double 0=open 1=open
*/
double randd_oo();
#ifdef __cplusplus
} // extern "C"
#endif
#endif // MERSENNE_TWISTER_H