tango.math.random.Twister

License:

BSD style: see license.txt

Version:

Jan 2008: Initial release

Author:

KeYeR (D interface) keyer@team0xf.com
struct Twister
Wrapper for the Mersenne twister. The Mersenne twister is a pseudorandom number generator linked to CR developed in 1997 by Makoto Matsumoto and Takuji Nishimura that is based on a matrix linear recurrence over a finite binary field F2. It provides for fast generation of very high quality pseudorandom numbers, having been designed specifically to rectify many of the flaws found in older algorithms. Mersenne Twister has the following desirable properties:
1
2
3
4
5
6
7
8
9
10
11
1. It was designed to have a period of 2^19937 - 1 (the creators
   of the algorithm proved this property).

2. It has a very high order of dimensional equidistribution.
   This implies that there is negligible serial correlation between
   successive values in the output sequence.

3. It passes numerous tests for statistical randomness, including
   the stringent Diehard tests.

4. It is fast.
Twister instance [public, gshared, static]
A global, shared instance, seeded via startup time
Twister opCall() [static]
Creates and seeds a new generator with the current time
uint natural(uint max)
Returns X such that 0 <= X < max
uint natural(uint min, uint max)
Returns X such that min <= X < max
uint natural(bool pAddEntropy = false)
Returns X such that 0 <= X <= uint.max
double inclusive()
generates a random number on [0,1] interval
double exclusive()
generates a random number on (0,1) interval
double fraction()
generates a random number on [0,1) interval
double fractionEx()
generates a random number on [0,1) with 53-bit resolution
void seed()
Seed the generator with current time
void seed(uint s, bool pAddEntropy = false)
initializes the generator with a seed
void init(const(uint[]) init_key, bool pAddEntropy = false)
initialize by an array with array-length init_key is the array for initializing keys