randomSubstreamSeedGet

Retrieves a seed for the congruential generators that do not do shuffling that will generate random numbers beginning 100,000 numbers farther along.

Synopsis

randomSubstreamSeedGet (iseed1)

Required Arguments

int iseed1 (Input)
The seed that yields the first stream.

Return Value

The seed that yields a stream beginning 100,000 numbers beyond the stream that begins with iseed1.

Description

Given a seed, iseed1, randomSubstreamSeedGet determines another seed, such that if one of the PyIMSL multiplicative congruential generators, using no shuffling, went through 100,000 generations starting with iseed1, the next number in that sequence would be the first number in the sequence that begins with the returned seed.

Note that randomSubstreamSeedGet works only when a multiplicative congruential generator without shuffling is used. This means that either the function randomOption has not been called at all or that it has been last called with generatorOption taking a value of 1, 3, or 5.

For many of the PyIMSL generators for nonuniform distributions that do not use the inverse CDF method, the distance between the sequences generated starting with iseed1 and starting with the returned seed may be less than 100,000. This is because the nonuniform generators that use other techniques may require more than one uniform deviate for each output deviate.

The reason that one may want two seeds that generate sequences a known distance apart is for blocking Monte Carlo experiments or for running parallel streams

Example

In this example, randomSubstreamSeedGet is used to determine seeds for 4 separate streams, each 200,000 numbers apart, for a multiplicative congruential generator without shuffling. (Since randomOption is not invoked to select a generator, the multiplier is 16807.) Since the streams are 200,000 numbers apart, each seed requires two invocations of randomSubstreamSeedGet. All of the streams are non-overlapping, since the period of the underlying generator is 2,147,483,646. The resulting seed are then verified by checking the seed after generating random sequences of length 200,000.

from __future__ import print_function
from numpy import *
from pyimsl.stat.randomSubstreamSeedGet import randomSubstreamSeedGet
from pyimsl.stat.randomSeedGet import randomSeedGet
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.randomUniform import randomUniform

is1 = 123457
is2 = randomSubstreamSeedGet(is1)
is2 = randomSubstreamSeedGet(is2)
is3 = randomSubstreamSeedGet(is2)
is3 = randomSubstreamSeedGet(is3)
is4 = randomSubstreamSeedGet(is3)
is4 = randomSubstreamSeedGet(is4)
print("Seeds for four separate streams:")
print(is1, is2, is3, is4)
randomSeedSet(is1)

seeds = []
for i in range(3):
    r = randomUniform(200000)
    seeds.append(randomSeedGet())
    print("Seed after %d random numbers: %d" % ((i + 1) * 200000, seeds[i]))

Output

Seeds for four separate streams:
123457 2016130173 85016329 979156171
Seed after 200000 random numbers: 2016130173
Seed after 400000 random numbers: 85016329
Seed after 600000 random numbers: 979156171