randomGfsrTableGet

Retrieves the current table used in the GFSR generator.

Synopsis

randomGfsrTableGet (table)

Required Arguments

int table (Output)
An array of length 1565 containing the table used in the GFSR generators. Typically, int table is declared and &table is used as an argument.

Description

The values in table are initialized by the PyIMSL random number generators. The values are all positive except if the user wishes to reinitialize the array, in which case the first element of the array is input as a nonpositive value. (Usually, one should avoid reinitializing these arrays, but it might be necessary sometimes in restarting a simulation.) If the first element of table is set to a nonpositive value on the call to randomGfsrTableSet, on the next invocation of a routine to generate random numbers using a GFSR method, the appropriate array will be reinitialized.

Example

In this example, three separate simulation streams are used, each with a different form of the generator. Each stream is stopped and restarted. (Although this example is obviously an artificial one, there may be reasons for maintaining separate streams and stopping and restarting them because of the nature of the usage of the random numbers coming from the separate streams.)

from __future__ import print_function
from numpy import *
from pyimsl.stat.randomGfsrTableGet import randomGfsrTableGet
from pyimsl.stat.randomGfsrTableSet import randomGfsrTableSet
from pyimsl.stat.randomOption import randomOption
from pyimsl.stat.randomSeedGet import randomSeedGet
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.randomTableGet import randomTableGet
from pyimsl.stat.randomTableSet import randomTableSet
from pyimsl.stat.randomUniform import randomUniform
from pyimsl.stat.writeMatrix import writeMatrix

nr = 5
iseed1 = 123457
iseed2 = 123457
iseed7 = 123457

# Begin first stream, iopt = 1 (by default)
randomSeedSet(iseed1)
r = randomUniform(nr)
iseed1 = randomSeedGet()
writeMatrix("First stream output", r,
            noColLabels=True, noRowLabels=True)

# Begin second stream, iopt = 2
randomOption(2)
randomSeedSet(iseed2)
r = randomUniform(nr)
iseed2 = randomSeedGet()
table = []
randomTableGet(table)
writeMatrix("Second stream output", r,
            noColLabels=True, noRowLabels=True)
print("    Output seed: ", iseed2)

# Begin third stream, iopt = 7
randomOption(7)
randomSeedSet(iseed7)
r = randomUniform(nr)
iseed7 = randomSeedGet()
itable = []
randomGfsrTableGet(itable)
writeMatrix("Third stream output", r,
            noColLabels=True, noRowLabels=True)
print("    Output seed: ", iseed7)

# Reinitialize and resume first stream
randomOption(1)
randomSeedSet(iseed1)
r = randomUniform(nr)
iseed1 = randomSeedGet()
writeMatrix("First stream output", r,
            noColLabels=True, noRowLabels=True)
print("    Output seed: ", iseed1)

# Reinitialize seed and table for shuffling and
# resume second stream
randomOption(2)
randomSeedSet(iseed2)
randomTableSet(table)
r = randomUniform(nr)
iseed2 = randomSeedGet()
writeMatrix("Second stream output", r,
            noColLabels=True, noRowLabels=True)
print("    Output seed: ", iseed2)

# Reinitialize seed and table for GFSR and
# resume third stream
randomOption(7)
randomSeedSet(iseed7)
randomGfsrTableSet(itable)
r = randomUniform(nr)
iseed7 = randomSeedGet()
writeMatrix("Third stream output", r,
            noColLabels=True, noRowLabels=True)
print("    Output seed: ", iseed7)

# Reset the random option
randomOption(1)

Output

    Output seed:  1965912801
    Output seed:  1932158269
    Output seed:  817878095
    Output seed:  2108806573
    Output seed:  1485334679
 
                      First stream output
     0.9662       0.2607       0.7663       0.5693       0.8448
 
                     Second stream output
     0.7095       0.1861       0.4794       0.6038       0.3790
 
                      Third stream output
     0.3914       0.0263       0.7622       0.0281       0.8997
 
                      First stream output
     0.0443       0.9872       0.6014       0.8964       0.3809
 
                     Second stream output
     0.2557       0.4788       0.2258       0.3455       0.5811
 
                      Third stream output
     0.7519       0.5084       0.9070       0.0910       0.6917