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