RandomTools[MersenneTwister]
NewGenerator
Mersenne Twister Pseudo Random Number Generator
Calling Sequence
Parameters
Description
Examples
NewGenerator( opt1, opt2, ... )
opt1, opt2, ...
-
(optional) argument of the form option=value where option is range
The NewGenerator command outputs a Maple procedure, a pseudo-random number generator, which when called outputs one pseudo-random integer. The output of the generator depends on the options described below. The default is to output integers on the range 0..999999999999, i.e., a random 12 digit integer.
The returned procedure calls the MersenneTwister algorithm to generate the numbers. Although you can have multiple generating procedures, they all share the same state. This means that calling one procedure will effect the numbers returned by another.
The following optional arguments are supported. They are input as equations in any order.
range=integer..integer or integer
If the value of the range argument is a range, then the integer will be chosen from that range. If the value of the range argument is an integer, then the integer will be take from the range [0..value). The default range is 1000000000000.
If one only needs to generate a small number of integers then the GenerateInteger function can be used. However, using a procedure returned by NewGenerator is faster than calling GenerateInteger multiple times.
with⁡RandomToolsMersenneTwister
GenerateData,GenerateFloat,GenerateFloat64,GenerateInteger,GenerateInteger32,GenerateUnsignedInt32,GetState,NewGenerator,SetState
M≔NewGenerator⁡range=1..6
M ≔ procprocoptionbuiltin=RandNumberInterface;end proc⁡6,6,3+1end proc
M⁡
5
seq⁡M⁡,i=1..10
2,5,6,2,3,4,4,6,5,3
M≔NewGenerator⁡range=1010
M ≔ procprocoptionbuiltin=RandNumberInterface;end proc⁡6,10000000000,34end proc
8451185402
seq⁡M⁡,i=1..5
7412421905,9061787218,3427838553,1275731771,20544909
Float⁡M⁡,−10
0.4777998714
seq⁡Float⁡M⁡,−10,i=1..5
0.8067798189,0.3427077306,0.5205175372,0.7221384230,0.2039073006
M≔NewGenerator⁡range=1032:
82579665362154732179876235348313
See Also
rand
RandomTools
RandomTools[BlumBlumShub]
RandomTools[Generate]
RandomTools[LinearCongruence]
RandomTools[QuadraticCongruence]
Download Help Document