Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
mir.random.engine.mersenne_twister
The Mersenne Twister generator.
License:
Authors:
Andrei Alexandrescu Ilya Yaroshenko (rework)
- struct
MersenneTwisterEngine
(UIntType, size_t w, size_t n, size_t m, size_t r, UIntType a, size_t u, UIntType d, size_t s, UIntType b, size_t t, UIntType c, size_t l, UIntType f) if (isUnsigned!UIntType); - The Mersenne Twister generator.
- enum auto
isRandomEngine
; - enum UIntType
max
; - Largest generated value.
- enum size_t
wordSize
;
enum size_tstateSize
;
enum size_tshiftSize
;
enum size_tmaskBits
;
enum UIntTypexorMask
;
enum size_ttemperingU
;
enum UIntTypetemperingD
;
enum size_ttemperingS
;
enum UIntTypetemperingB
;
enum size_ttemperingT
;
enum UIntTypetemperingC
;
enum size_ttemperingL
;
enum UIntTypeinitializationMultiplier
; - Parameters for the generator.
- enum UIntType
defaultSeed
; - The default seed value.
- size_t
index
; - Current reversed payload index with initial value equals to n-1
- UIntType[n]
data
; - Reversed(!) payload.
- pure nothrow @nogc @safe this(UIntType
value
); - Constructs a MersenneTwisterEngine object.
- pure nothrow @nogc @safe this()(scope const(UIntType)[]
array
); - Constructs a MersenneTwisterEngine object.Note that MersenneTwisterEngine([123]) will not result in the same initial state as MersenneTwisterEngine(123).
- pure nothrow @nogc @safe UIntType
opCall
(); - Advances the generator.
- alias
Mt19937
= MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u).MersenneTwisterEngine; - A MersenneTwisterEngine instantiated with the parameters of the original engine MT19937, generating uniformly-distributed 32-bit numbers with a period of 2 to the power of 19937.This is recommended for random number generation on 32-bit systems unless memory is severely restricted, in which case a Xorshift would be the generator of choice.Examples:
import mir.random.engine; // bit-masking by generator maximum is necessary // to handle 64-bit `unpredictableSeed` auto gen = Mt19937(unpredictableSeed & Mt19937.max); auto n = gen(); import std.traits; static assert(is(ReturnType!gen == uint));
- alias
Mt19937_64
= MersenneTwisterEngine!(ulong, 64LU, 312LU, 156LU, 31LU, 13043109905998158313LU, 29LU, 6148914691236517205LU, 17LU, 8202884508482404352LU, 37LU, 18444473444759240704LU, 43LU, 6364136223846793005LU).MersenneTwisterEngine; - A MersenneTwisterEngine instantiated with the parameters of the original engine MT19937, generating uniformly-distributed 64-bit numbers with a period of 2 to the power of 19937.This is recommended for random number generation on 64-bit systems unless memory is severely restricted, in which case a Xorshift would be the generator of choice.Examples:
import mir.random.engine; auto gen = Mt19937_64(unpredictableSeed); auto n = gen(); import std.traits; static assert(is(ReturnType!gen == ulong));
Copyright © 2016-2021 by Ilya Yaroshenko | Page generated by
Ddoc on Tue Mar 23 21:30:37 2021