CNL Stat : Random Number Generation : random_substream_seed_get
random_substream_seed_get
Retrieves a seed for the congruential generators that do not do shuffling that will generate random numbers beginning 100,000 numbers farther along.
Synopsis
#include <imsls.h>
int imsls_random_substream_seed_get (int 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, imsls_random_substream_seed_get determines another seed, such that if one of the IMSL 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 imsls_random_substream_seed_get works only when a multiplicative congruential generator without shuffling is used. This means that either the function imsls_random_option has not been called at all or that it has been last called with generator_option taking a value of 1, 3, or 5.
For many of the IMSL 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, imsls_random_substream_seed_get is used to determine seeds for 4 separate streams, each 200,000 numbers apart, for a multiplicative congruential generator without shuffling. (Since imsls_random_option 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 imsls_random_substream_seed_get. 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.
 
#include <imsls.h>
#include <stdio.h>
 
int main()
{
int i, is1, is2, is3, is4;
float *r;
 
is1 = 123457;
is2 = imsls_random_substream_seed_get(is1);
is2 = imsls_random_substream_seed_get(is2);
is3 = imsls_random_substream_seed_get(is2);
is3 = imsls_random_substream_seed_get(is3);
is4 = imsls_random_substream_seed_get(is3);
is4 = imsls_random_substream_seed_get(is4);
 
printf("Seeds for four separate streams:\n");
printf("%d\t%d\t%d\t%d\n\n", is1, is2, is3, is4);
 
imsls_random_seed_set(is1);
 
for (i=0;i<3;i++) {
r = imsls_f_random_uniform(200000,
0);
 
printf("seed after %d random numbers: %d\n", (i + 1) * 200000,
imsls_random_seed_get());
 
if (r)
imsls_free(r);
}
}
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