Mersenne Twister #
Generic implementation for the Mersenne Twister pseudorandom number generator.
All choices of parameters from Matsumoto and Nishimura (1998) are supported, along with later
refinements. Parameters for the standard 32-bit MT19937 and 64-bit MT19937-64 algorithms are
provided. Both RandomGen
and Stream
interfaces are provided.
Use mt19937.init seed
to create a MT19937 PRNG with a 32 bit seed value; use
mt19937_64.init seed
to create a MT19937-64 PRNG with a 64 bit seed value. If omitted, default
seed choices will be used.
Sample usage:
import Batteries.Data.Random.MersenneTwister
open Batteries.Random.MersenneTwister
def mtgen := mt19937.init -- default seed 4357
#eval (Stream.take mtgen 5).fst -- [874448474, 2424656266, 2174085406, 1265871120, 3155244894]
References: #
Matsumoto, Makoto and Nishimura, Takuji (1998), Mersenne twister: A 623-dimensionally equidistributed uniform pseudo-random number generator, ACM Trans. Model. Comput. Simul. 8, No. 1, 3-30. ZBL0917.65005.
Nishimura, Takuji (2000), Tables of 64-bit Mersenne twisters, ACM Trans. Model. Comput. Simul. 10, No. 4, 348-357. ZBL1390.65014.
Mersenne Twister configuration.
Letters in parentheses correspond to variable names used by Matsumoto and Nishimura (1998) and Nishimura (2000).
- wordSize : Nat
Word size (
w
). - stateSize : Nat
Degree of recurrence (
n
). Middle word (
m
).Twist value (
r
).Coefficients of the twist matrix (
a
).Tempering shift parameters (
u
,s
,t
,l
).Tempering mask parameters (
d
,b
,c
).Initialization multiplier (
f
).Default initialization seed value.
Instances For
Apply the twisting transformation to the given state.
Equations
Instances For
32 bit Mersenne Twister (MT19937) configuration.
Equations
Instances For
64 bit Mersenne Twister (MT19937-64) configuration.