randomMt32TableGet

Retrieves the current table used in the 32-bit Mersenne Twister generator.

Synopsis

randomMt32TableGet (table)

Required Arguments

unsigned int table (Output)
An array of length 625 containing the table used in the 32-bit Mersenne Twister generator. Typically, unsigned int table is declared and &table is used as an argument.

Description

The values in table contain the state of the 32-bit Mersenne Twister random number generator. The table can be used by randomMt32TableSet 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.randomMt32Init import randomMt32Init
from pyimsl.stat.randomMt32TableGet import randomMt32TableGet
from pyimsl.stat.randomMt32TableSet import randomMt32TableSet
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 Mersenne twister series with a seed
randomOption(8)
randomSeedSet(iseed)
r = randomUniform(nr)
writeMatrix("First stream output", r,
            noColLabels=True, noRowLabels=True)

# Reinitialize Mersenne twister series with an array
randomOption(8)
randomMt32Init(init)

# Save the state of the series
itable = []
randomMt32TableGet(itable)
r = randomUniform(nr)
writeMatrix("Second stream output", r,
            noColLabels=True, noRowLabels=True)

# Restore the state of the series
randomMt32TableSet(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
randomMt32TableSet(itable)
r = randomUniform(nr)
writeMatrix("Fourth stream output", r,
            noColLabels=True, noRowLabels=True)

# Reset the random option
randomOption(1)

Output

 
                      First stream output
     0.4347       0.3522       0.0139       0.2091       0.4956
 
                     Second stream output
     0.2486       0.2226       0.1111       0.9563       0.9846
 
                      Third stream output
     0.2486       0.2226       0.1111       0.9563       0.9846
 
                     Fourth stream output
     0.4347       0.3522       0.0139       0.2091       0.4956