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. 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.

Members

Aliases

toInt
alias toInt = natural
Undocumented in source.
toReal
alias toReal = fraction
Undocumented in source.

Functions

exclusive
double exclusive()

generates a random number on (0,1) interval

fraction
double fraction()

generates a random number on [0,1) interval

fractionEx
double fractionEx()

generates a random number on [0,1) with 53-bit resolution

inclusive
double inclusive()

generates a random number on [0,1] interval

init
void init(uint[] init_key, bool pAddEntropy)

initialize by an array with array-length init_key is the array for initializing keys

natural
uint natural(uint max)

Returns X such that 0 <= X < max

natural
uint natural(uint min, uint max)

Returns X such that min <= X < max

natural
uint natural(bool pAddEntropy)

Returns X such that 0 <= X <= uint.max

seed
void seed()

Seed the generator with current time

seed
void seed(uint s, bool pAddEntropy)

initializes the generator with a seed

Static functions

opCall
Twister opCall()

Creates and seeds a new generator with the current time

Static variables

instance
Twister instance;

A global, shared instance, seeded via startup time

Meta