IMSL Mathematics Reference Guide > Basic Statistics and Random Number Generation > RANDOMOPT Procedure (PV-WAVE Advantage)
  

RANDOMOPT Procedure (PV-WAVE Advantage)
Uses keywords to set or retrieve the random number seed or to select the form of the IMSL random number generator.
Usage
RANDOMOPT
Input Parameters
Procedure RANDOMOPT does not have any positional Input Parameters. Keywords are required for specific actions to be taken.
Input Keywords
Gen_Option—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.
*1multiplier 16807 used (default)
*2multiplier 16807 used with shuffling
*3multiplier 397204094 used
*4multiplier 397204094 used with shuffling
*5multiplier 950706376 used
*6multiplier 950706376 used with shuffling
*7GFSR, with the recursion is used.
*8—A 32-bit Mersenne Twister generator is used. The float and double random numbers are generated from 32-bit integers.
*9—A 64-bit Mersenne Twister generator is used. The float and double random numbers are generated from 64-bit integers. This ensures that all bits of both float and doubles are random.
Set—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 PV‑WAVE IMSL Statistics random-number generators are different at various times.
Substream_seed—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.
Output Keywords
Get—Named variable into which the value of the current random-number seed is stored.
Current_option—Named variable into which the value of the current random-number generator option is stored.
Discussion
Procedure RANDOMOPT 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 function 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 PV‑WAVE IMSL Statistics random-number generators. See the chapter introduction for details of the various gererator options. The seed can be reinitialized to a clock-dependent value by calling 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, RANDOMOPT determines another seed, such that if one of the 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 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 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.
Both of the Mersenne Twister generators have a period of 219937-1 and a 623-dimensional equidistribution property. See Matsumoto et al. 1998 for details.
The Mersenne Twister generators are derived from code copyright (C) 1997–2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. It is subject to the following notice:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The 32-bit Mersenne Twister generator is based on the Matsumoto and Nishimura code ‘mt19937ar’ and the 64-bit code is based on ‘mt19937-64’.
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
; Set the seed using the keyword Set.
RANDOMOPT, Set = seed
r1 = RANDOM(nrandom)
PM, r1, Title = 'First Group of Random Numbers'
; PV-WAVE prints the following:
; First Group of Random Numbers
;    0.966220
;    0.260711
;    0.766262
;    0.569337
;    0.844829
; Get the current value of the seed using the keyword Get.
RANDOMOPT, Get = seed
; Set the seed. 
RANDOMOPT, Set = seed
r2 = RANDOM(nrandom)
PM, r2, Title = 'Second Group of Random Numbers'
; PV-WAVE prints the following:
; Second Group of Random Numbers
;    0.0442665
;    0.987184
;    0.601350
;    0.896375
;    0.380854
; Reset the seed to the original seed.
RANDOMOPT, Set = 123457
r3 = RANDOM(2 * nrandom)
PM, r3, Title = 'Both Groups of Random Numbers'
; PV-WAVE prints the following:
; 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, RANDOMOPT is used to determine seeds for 4 separate streams, each 200,000 numbers apart, for a multiplicative congruential generator without shuffling. (Since 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 RANDOMOPT with keyword Substream_seed. All of the streams are non-overlapping, since the period of the underlying generator is 2,147,483,646.
RANDOMOPT, GEN_OPTION = 1
is1 = 123457;
RANDOMOPT, Get = itmp, Substream_seed = is1
RANDOMOPT, Get = is2, Substream _seed = itmp
RANDOMOPT, Get = itmp, Substream _seed = is2
RANDOMOPT, Get = is3, Substream _seed = itmp
RANDOMOPT, Get = itmp, Substream _seed = is3
RANDOMOPT, Get = is4, Substream _seed = itmp
PRINT, is1, is2, is3, is4
   ; PV-WAVE prints: 123457  2016130173    85016329   979156171

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.