randomMt64TableGet¶
Retrieves the current table used in the 64-bit Mersenne Twister generator.
Synopsis¶
randomMt64TableGet (table)
Required Arguments¶
- unsigned long long
table
(Output) - An array of length 625 containing the table used in the 64-bit Mersenne
Twister generator. Typically, unsigned long long
table
is declared and&table
is used as an argument.
Description¶
The values in the table
contain the state of the 64-bit Mersenne Twister
random number generator. The table can be used by
randomMt64TableSet to set the generator back to this
state.
Example¶
In this example, four simulation streams are generated. The first series is generated with the seed used for initialization. The second series is generated using an array for initialization. The third series is obtained by resetting the generator back to the state it had at the beginning of the second stream. Therefore the second and third streams are identical. The fourth stream is obtained by resetting the generator back to its original, uninitialized state, and having it reinitialize using the seed. The fourth and first streams are therefore the same.
from numpy import *
from pyimsl.stat.randomMt64Init import randomMt64Init
from pyimsl.stat.randomMt64TableGet import randomMt64TableGet
from pyimsl.stat.randomMt64TableSet import randomMt64TableSet
from pyimsl.stat.randomOption import randomOption
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.randomUniform import randomUniform
from pyimsl.stat.writeMatrix import writeMatrix
init = [0x123, 0x234, 0x345, 0x456]
iseed = 123457
nr = 5
# Initialize 64-bit Mersenne Twister series with a seed
randomOption(9)
randomSeedSet(iseed)
r = randomUniform(nr)
writeMatrix("First stream output", r,
noColLabels=True, noRowLabels=True)
# Reinitialize Mersenne Twister series with an array
randomOption(9)
randomMt64Init(init)
# Save the state of the series
itable = []
randomMt64TableGet(itable)
r = randomUniform(nr)
writeMatrix("Second stream output", r,
noColLabels=True, noRowLabels=True)
# Restore the state of the series
randomMt64TableSet(itable)
r = randomUniform(nr)
writeMatrix("Third stream output", r,
noColLabels=True, noRowLabels=True)
# Reset the series - it will reinitialize from the seed
itable[0] = 1000
randomMt64TableSet(itable)
r = randomUniform(nr)
writeMatrix("Fourth stream output", r,
noColLabels=True, noRowLabels=True)
# Reset the random option so subsequent tests will work
randomOption(1)
Output¶
First stream output
0.5799 0.9401 0.7102 0.1640 0.5457
Second stream output
0.4894 0.7397 0.5725 0.0863 0.7588
Third stream output
0.4894 0.7397 0.5725 0.0863 0.7588
Fourth stream output
0.5799 0.9401 0.7102 0.1640 0.5457