QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
src
analysis
vector
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
#ifndef _MSC_VER
28
#include <stdint.h>
29
#else
30
typedef
__int32 int32_t;
31
typedef
unsigned
__int32 uint32_t;
32
typedef
__int64 int64_t;
33
typedef
unsigned
__int64 uint64_t;
34
#endif
35
#include <limits>
36
37
#ifdef __cplusplus
38
extern
"C"
39
{
40
#endif
41
42
/*
43
* Maximum number you can get from rand().
44
*/
45
#define MD_RAND_MAX std::numeric_limits<int32_t>::max()
46
47
/*
48
* Initialize the number generator with given seed.
49
* (LIBC REPLACEMENT FUNCTION)
50
*/
51
void
mt_srand
(
unsigned
seed_value );
52
53
/*
54
* Extract a pseudo-random integer in the range 0 ... MD_RAND_MAX.
55
* (LIBC REPLACEMENT FUNCTION)
56
*/
57
int
mt_rand
();
58
59
/*
60
* Extract a pseudo-random unsigned 32-bit integer in the range 0 ... MD_UINT32_MAX
61
*/
62
uint32_t
rand_u32
();
63
64
/*
65
* Combine two unsigned 32-bit pseudo-random numbers into one 64-bit
66
*/
67
uint64_t
rand_u64
();
68
69
/*
70
* Initialize Mersenne Twister with given seed value.
71
*/
72
void
seed
( uint32_t seed_value );
73
74
/*
75
* Return a random float in the CLOSED range [0, 1]
76
* Mnemonic: randf_co = random float 0=closed 1=closed
77
*/
78
float
randf_cc
();
79
80
/*
81
* Return a random float in the OPEN range [0, 1>
82
* Mnemonic: randf_co = random float 0=closed 1=open
83
*/
84
float
randf_co
();
85
86
/*
87
* Return a random float in the OPEN range <0, 1>
88
* Mnemonic: randf_oo = random float 0=open 1=open
89
*/
90
float
randf_oo
();
91
92
/*
93
* Return a random double in the CLOSED range [0, 1]
94
* Mnemonic: randd_co = random double 0=closed 1=closed
95
*/
96
double
randd_cc
();
97
98
/*
99
* Return a random double in the OPEN range [0, 1>
100
* Mnemonic: randd_co = random double 0=closed 1=open
101
*/
102
double
randd_co
();
103
104
/*
105
* Return a random double in the OPEN range <0, 1>
106
* Mnemonic: randd_oo = random double 0=open 1=open
107
*/
108
double
randd_oo
();
109
110
#ifdef __cplusplus
111
}
// extern "C"
112
#endif
113
114
#endif // MERSENNE_TWISTER_H
randf_co
float randf_co()
Definition:
mersenne-twister.cpp:201
seed
void seed(uint32_t seed_value)
Definition:
mersenne-twister.cpp:111
mt_rand
int mt_rand()
Definition:
mersenne-twister.cpp:171
mt_srand
void mt_srand(unsigned seed_value)
Definition:
mersenne-twister.cpp:191
randf_cc
float randf_cc()
Definition:
mersenne-twister.cpp:196
randd_cc
double randd_cc()
Definition:
mersenne-twister.cpp:211
randf_oo
float randf_oo()
Definition:
mersenne-twister.cpp:206
randd_oo
double randd_oo()
Definition:
mersenne-twister.cpp:221
randd_co
double randd_co()
Definition:
mersenne-twister.cpp:216
rand_u64
uint64_t rand_u64()
Definition:
mersenne-twister.cpp:226
rand_u32
uint32_t rand_u32()
Definition:
mersenne-twister.cpp:152
Generated on Sun Jun 24 2018 11:42:48 for QGIS API Documentation by
1.8.13