RandomTools[LinearCongruence]
NewGenerator
Create a Linear Congruence 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 LinearCongruence 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⁡RandomToolsLinearCongruence
GenerateInteger,GetState,NewGenerator,SetState
M≔NewGenerator⁡range=1..6
M ≔ procLinearCongruence:-LCState ≔ irem⁡427419669081*LinearCongruence:-LCState,999999999989;irem⁡LinearCongruence:-LCState,6+1end proc
M⁡
4
seq⁡M⁡,i=1..10
3,4,6,5,3,6,3,2,2,2
M≔NewGenerator⁡range=1010
M ≔ procLinearCongruence:-LCState ≔ irem⁡427419669081*LinearCongruence:-LCState,999999999989;irem⁡LinearCongruence:-LCState,10000000000end proc
75487163
seq⁡M⁡,i=1..5
7179490457,9169594160,8430571674,498834085,2920457916
Float⁡M⁡,−10
0.3747019461
seq⁡Float⁡M⁡,−10,i=1..5
0.4031395307,0.0624947349,0.1053530086,0.6486307198,0.5590763466
M≔NewGenerator⁡range=1032
M ≔ proclocalt;LinearCongruence:-LCState ≔ irem⁡427419669081*LinearCongruence:-LCState,999999999989;t ≔ LinearCongruence:-LCState;to2doLinearCongruence:-LCState ≔ irem⁡427419669081*LinearCongruence:-LCState,999999999989;t ≔ 1000000000000*t+LinearCongruence:-LCStateend do;irem⁡t,100000000000000000000000000000000end proc
92673709525428510973272600608981
See Also
rand
RandomTools
RandomTools[Generate]
RandomTools[LinearCongruence][GenerateInteger]
Download Help Document