>  Docs Center  >  IDL Reference  >  Advanced Math and Stats  >  IMSL_RANDOMOPT

IMSL_RANDOMOPT

IMSL_RANDOMOPT

The IMSL_RANDOMOPT procedure uses keywords to set or retrieve the random number seed or to select the form of the IMSL random number generator.

This routine requires an IDL Advanced Math and Stats license. For more information, contact your sales or technical support representative.

The IMSL_RANDOMOPT procedure is designed to allow a user to set certain key elements of the random-number generator functions.

The uniform pseudorandom-number generators use a multiplicative congruential method, or a generalized feedback shift register. The choice of generator is determined by keyword GEN_OPTION. The chapter introduction and the description of IMSL_RANDOM may provide some guidance in the choice of the form of the generator. If no selection is made explicitly, the generators use the multiplier 16807 without shuffling. This form of the generator has been in use for some time (Lewis et al. 1969).

Keyword SET is used to initialize the seed used in the IDL Advanced Math and Stats random-number generators. See the introduction for details of the various generator options. The seed can be reinitialized to a clock-dependent value by calling IMSL_RANDOMOPT with SET set to zero.

A common use of keyword Set is in conjunction with the keyword Get to restart a simulation. Keyword Get retrieves the current value of the “seed” used in the random-number generators.

If keyword SUBSTREAM_SEED is set, IMSL_RANDOMOPT determines another seed, such that if one of the IMSL multiplicative congruential generators, using no shuffling, went through 100,000 generations starting with SUBSTREAM_SEED, the next number in that sequence would be the first number in the sequence that begins with the returned seed.

Note that SUBSTREAM_SEED works only when a multiplicative congruential generator without shuffling is used. This means that either the routine IMSL_RANDOMOPT has not been called at all or that it has been last called with GEN_OPTION having a value of 1, 3, or 5.

For many IMSL generators for nonuniform distributions that do not use the inverse CDF method, the distance between sequences generated starting with SUBSTREAM_SEED and starting with returned seed may be less than 100,000. This is because 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.

Examples


Example 1

This example illustrates the statements required to restart a simulation using the keywords GET and SET. The example shows that restarting the sequence of random numbers at the value of the last seed generated is the same as generating the random numbers all at once.

seed = 123457
nrandom = 5
IMSL_RANDOMOPT, Set = seed
; Set the seed using the keyword Set.
r1 = IMSL_RANDOM(nrandom)
PM, r1, Title = 'First Group of Random Numbers'
 
First Group of Random Numbers
0.966220
0.260711
0.766262
0.569337
0.844829
 
IMSL_RANDOMOPT, Get = seed
; Get the current value of the seed using the keyword Get.
IMSL_RANDOMOPT, Set = seed
; Set the seed.
r2 = IMSL_RANDOM(nrandom)
PM, r2, Title = 'Second Group of Random Numbers'
 
Second Group of Random Numbers
0.0442665
0.987184
0.601350
0.896375
0.380854
 
IMSL_RANDOMOPT, Set = 123457
; Reset the seed to the original seed.
r3 = IMSL_RANDOM(2 * nrandom)
PM, r3, Title = 'Both Groups of Random Numbers'
 
Both Groups of Random Numbers
0.966220
0.260711
0.766262
0.569337
0.844829
0.0442665
0.987184
0.601350
0.896375
0.380854

Example 2

In this example, IMSL_RANDOMOPT is used to determine seeds for 4 separate streams, each 200,000 numbers apart, for a multiplicative congruential generator without shuffling. (Since IMSL_RANDOMOPT 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 IMSL_RANDOMOPT with keyword SUBSTREAM_SEED. All of the streams are non-overlapping, since the period of the underlying generator is 2,147,483,646.

IMSL_RANDOMOPT, GEN_OPTION = 1
is1 = 123457;
IMSL_RANDOMOPT, GET = itmp, SUBSTREAM_SEED = is1
IMSL_RANDOMOPT, GET = is2, SUBSTREAM_SEED = itmp
IMSL_RANDOMOPT, GET = itmp, SUBSTREAM_SEED = is2
IMSL_RANDOMOPT, GET = is3, SUBSTREAM_SEED = itmp
IMSL_RANDOMOPT, GET = itmp, SUBSTREAM_SEED = is3
IMSL_RANDOMOPT, GET = is4, SUBSTREAM_SEED = itmp
PRINT, is1, is2, is3, is4
 
123457 2016130173 85016329 979156171

Syntax


IMSL_RANDOMOPT ([, CURRENT_OPTION=variable] [, GEN_OPTION=value] [, GET_SEED=variable] [, SET_SEED=value] [, SUBSTREAM_SEED=value])

Return Value


None

Arguments


The IMSL_RANDOMOPT procedure does not have any positional Input Parameters.

Keywords are required for specific actions to be taken.

Keywords


CURRENT_OPTION (optional)

Named variable into which the value of the current random-number generator option is stored.

GEN_OPTION (optional)

Indicator of the generator. The random-number generator is a multiplicative, congruential generator with modulus 231 – 1. Keyword GEN_OPTION is used to choose the multiplier and to determine whether or not shuffling is done.

  • 1: multiplier 16807 used (default)
  • 2: multiplier 16807 used with shuffling
  • 3: multiplier 397204094 used
  • 4: multiplier 397204094 used with shuffling
  • 5: multiplier 950706376 used
  • 6: multiplier 950706376 used with shuffling
  • 7: GFSR, with the recursion Xt = Xt-1563 ⊕ Xt-96 is used

GET_SEED (optional)

Named variable into which the value of the current random-number seed is stored.

SET_SEED (optional)

Seed of the random-number generator. The seed must be in the range (0, 2147483646). If the seed is zero, a value is computed using the system clock; hence, the results of programs using the IDL Advanced Math and Stats random-number generators are different at various times.

SUBSTREAM_SEED (optional)

If present and nonzero, then a seed for the congruential generators that do not do shuffling that will generate random numbers beginning 100,000 numbers farther along will be returned in keyword Get. If keyword SUBSTREAM_SEED is set, then keyword GET is required.

Version History


6.4

Introduced

See Also


IMSL_RANDOM, Overview of Random Number Generation



© 2019 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us