Mersenne twister pseudorandom number generator.
More...
#include <geomc/random/MTRand.h>
|
| MTRand (uint64_t seed) |
|
virtual void | rseed (uint64_t seed) |
| Reset the generator's state with the bits of seed as its source of entropy. More...
|
|
virtual uint32_t | rand32 () |
|
template<typename T > |
T | rand () |
|
template<typename T > |
T | rand (T max) |
|
template<typename T > |
T | rand (T lo, T hi) |
|
template<> |
bool | rand () |
|
template<> |
unsigned int | rand () |
|
template<> |
int | rand () |
|
template<> |
unsigned long | rand () |
|
template<> |
long | rand () |
|
template<> |
unsigned long long | rand () |
|
template<> |
long long | rand () |
|
template<> |
float | rand () |
|
template<> |
double | rand () |
|
template<> |
unsigned int | rand (unsigned int hi) |
|
template<> |
int | rand (int hi) |
|
template<> |
unsigned long | rand (unsigned long hi) |
|
template<> |
long | rand (long hi) |
|
template<> |
unsigned long long | rand (unsigned long long hi) |
|
template<> |
long long | rand (long long hi) |
|
template<> |
float | rand (float hi) |
|
template<> |
double | rand (double hi) |
|
template<> |
int | rand (int lo, int hi) |
|
template<> |
long long | rand (long long lo, long long hi) |
|
template<> |
float | rand (float lo, float hi) |
|
template<> |
double | rand (double lo, double hi) |
|
template<> |
bool | rand () |
|
template<> |
unsigned int | rand () |
|
template<> |
int | rand () |
|
template<> |
unsigned long | rand () |
|
template<> |
long | rand () |
|
template<> |
unsigned long long | rand () |
|
template<> |
long long | rand () |
|
template<> |
float | rand () |
|
template<> |
double | rand () |
|
template<> |
unsigned int | rand (unsigned int hi) |
|
template<> |
int | rand (int hi) |
|
template<> |
unsigned long | rand (unsigned long hi) |
|
template<> |
long | rand (long hi) |
|
template<> |
unsigned long long | rand (unsigned long long hi) |
|
template<> |
long long | rand (long long hi) |
|
template<> |
float | rand (float hi) |
|
template<> |
double | rand (double hi) |
|
template<> |
int | rand (int lo, int hi) |
|
template<> |
long long | rand (long long lo, long long hi) |
|
template<> |
float | rand (float lo, float hi) |
|
template<> |
double | rand (double lo, double hi) |
|
|
uint32_t | _bitpool |
|
unsigned int | _bitsleft |
|
Mersenne twister pseudorandom number generator.
Advantages:
- Very long period (does not repeat after a practically-attainable number of iterations)
- High-quality random numbers (no patterns; matches uniform distribution)
- Fast
Disadvantages:
- NOT cryptographically secure! Future random numbers can be predicted after observing a small number of samples.
- Don't use for security/cryptography
- Don't use for gambling
◆ rand() [1/24]
Produces a (pseudo-) random T
with uniform distribution over the unit interval, if the unit interval is populated by T
; or with uniform distribution over the entire space of possible T
otherwise.
For example, rand<float>()
returns a random float between 0 and 1.0, while rand<unsigned int>()
returns a random uint
between 0 and UINT_MAX
.
◆ rand() [2/24]
- Returns
- A random boolean value.
◆ rand() [3/24]
- Returns
- An
unsigned int
between 0 and UINT_MAX
.
◆ rand() [4/24]
- Returns
- An
int
between INT_MIN
and INT_MAX
.
◆ rand() [5/24]
- Returns
- An
unsigned long
between 0 and ULONG_MAX
.
◆ rand() [6/24]
- Returns
- A
long
between LONG_MIN
and LONG_MAX
.
◆ rand() [7/24]
unsigned long long rand |
( |
| ) |
|
|
inherited |
- Returns
- An
unsigned long long
betwen 0 and ULLONG_MAX
.
◆ rand() [8/24]
- Returns
- A
long long
between LLONG_MIN
and LLONG_MAX
.
◆ rand() [9/24]
Generate a floating-point value with uniform distribution between 0 and 1.0.
This method is preferable to use over the common practice of rand<int>() / (float)INT_MAX
, as the latter excludes a large fraction of the representable floating point numbers between 0.0 and 1.0 (particularly those near zero), resulting in reduced entropy.
This method produces a number by carefully picking the bits of the exponent and mantissa explicitly, in such a way that the distibution remains uniform.
◆ rand() [10/24]
Generate a floating-point value with uniform distribution between 0 and 1.0.
This method is preferable to use over the common practice of rand<int>() / (float)INT_MAX
, as the latter excludes a large fraction of the representable floating point numbers between 0.0 and 1.0 (particularly those near zero), resulting in reduced entropy.
This method produces a number by carefully picking the bits of the exponent and mantissa explicitly, in such a way that the distibution remains uniform.
◆ rand() [11/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
double
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [12/24]
double rand |
( |
double |
lo, |
|
|
double |
hi |
|
) |
| |
|
inherited |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- An
double
between lo
and hi
.
◆ rand() [13/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
float
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [14/24]
float rand |
( |
float |
lo, |
|
|
float |
hi |
|
) |
| |
|
inherited |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- An
float
between lo
and hi
.
◆ rand() [15/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A number between 0 and
hi
(regardless of the sign of hi
).
◆ rand() [16/24]
int rand |
( |
int |
lo, |
|
|
int |
hi |
|
) |
| |
|
inherited |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- An
int
between lo
and hi
.
◆ rand() [17/24]
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
long
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [18/24]
long long rand |
( |
long long |
hi | ) |
|
|
inherited |
- Parameters
-
hi | Upper or lower bound of random number. |
- Returns
- A
long long
between 0 and hi
, regardless of the sign of hi
.
◆ rand() [19/24]
long long rand |
( |
long long |
lo, |
|
|
long long |
hi |
|
) |
| |
|
inherited |
- Parameters
-
lo | Lower bound of random number. |
hi | Upper bound of random number. |
- Returns
- A
long long
between lo
and hi
.
◆ rand() [20/24]
Produces a (pseudo-) random T
with uniform distribution between lo
and hi
.
- Parameters
-
lo | Lower bound for possible T samples. |
hi | Upper bound for possible T samples. |
◆ rand() [21/24]
Produces a (pseudo-) random T
with uniform distribution between the T
analogue of 0
and max
.
- Parameters
-
max | Upper bound of possible T samples. |
◆ rand() [22/24]
unsigned int rand |
( |
unsigned int |
hi | ) |
|
|
inherited |
- Parameters
-
hi | Upper bound of random number. |
- Returns
- An
unsigned int
between 0 and hi
.
◆ rand() [23/24]
unsigned long rand |
( |
unsigned long |
hi | ) |
|
|
inherited |
- Parameters
-
hi | Upper bound of random number. |
- Returns
- An
unsigned long
between 0 and hi
.
◆ rand() [24/24]
unsigned long long rand |
( |
unsigned long long |
hi | ) |
|
|
inherited |
- Parameters
-
hi | Upper bound of random number. |
- Returns
- An
unsigned long long
between 0 and hi
.
◆ rand32()
- Returns
- No fewer than 32 (pseudo-) random bits.
Implements Random.
◆ rseed()
void rseed |
( |
uint64_t |
seed | ) |
|
|
virtual |
Reset the generator's state with the bits of seed
as its source of entropy.
Implements Random.
The documentation for this class was generated from the following files:
- geomc/random/MTRand.h
- geomc/random/MTRand.cpp