>  Docs Center  >  IDL Reference  >  Advanced Math and Stats  >  Overview: Random Number Generation

Overview: Random Number Generation

Overview of Random Number Generation

This section describes random number generation functions used for applications in Monte Carlo or simulation studies. Before using random number generators, the generator must be initialized by selecting a seed or starting value. You can do this by using IMSL_RANDOMOPT. If you do not select a seed, one is generated using the system clock. A seed needs to be selected only once in a program, unless two or more separate streams of random numbers are maintained. Utility functions in this section can be used to select the form of the basic generator to restart simulations and to maintain separate simulation streams.

In the following sections, the terms random numbers, random deviates, deviates, and variates are used interchangeably. The phrase pseudorandom is sometimes used to emphasize that the numbers generated are really not random since they result from a deterministic process. The usefulness of pseudorandom numbers is derived from the similarity, in a statistical sense, of samples of the pseudorandom numbers to samples of observations from the specified distributions. In short, while the pseudorandom numbers are deterministic and repeatable, they simulate the realizations of independent and identically distributed random variables.

Basic Uniform Generator

The default action of the IMSL_RANDOM function is the generation of uniform (0, 1) numbers. This function is portable in that, given the same seed, it produces the same sequence in all computer/compiler environments.

The random number generators in this chapter use either a multiplicative congruential method or a generalized feedback shift register (GFSR) method. The selection of the type of generator is made by calling the IMSL_RANDOMOPT. If no selection is made explicitly, a multiplicative generator (with multiplier 16807) is used. Whatever distribution is being simulated, uniform (0, 1) numbers are first generated and then transformed if necessary. These routines are portable in the sense that, given the same seed and for a given type of generator, they produce the same sequence in all computer/compiler environments. There are many other issues that must be considered in developing programs for the methods described below (see Gentle 1981 and 1990).

Multiplicative Congruential Generators

The form of the multiplicative congruential generators is:

xi ≡ cxi-1mod (231 - 1)

Each xi is then scaled into the unit interval (0, 1). If the multiplier, c, is a primitive root modulo 231 - 1 (which is a prime), then the generator will have a maximal period of 231 - 2. There are several other considerations, however. See Knuth (1981) for a good general discussion. The possible values for c in the generators are 16807, 397204094, and 950706376. The selection is made by IMSL_RANDOMOPT. The choice of 16807 will result in the fastest execution time, but other evidence suggests that the performance of 950706376 is best among these three choices (Fishman and Moore 1982). If no selection is made explicitly, the functions use the multiplier 16807, which has been in use for some time (Lewis et al. 1969).

Shuffled Generators

You also can select a shuffled version of these generators using IMSL_RANDOMOPT. The shuffled generators use a scheme due to Learmonth and Lewis (1973). In this scheme, a table is filled with the first 128 uniform (0, 1) numbers resulting from the simple multiplicative congruential generator. Then, for each xi from the simple generator, the low-order bits of xi are used to select a random integer, j, from 1 to 128. The j-th entry in the table is then delivered as the random number; and xi, after being scaled into the unit interval, is inserted into the j-th position in the table. This scheme is similar to that of Bays and Durham (1976), and their analysis is applicable to this scheme as well.

Generalized Feedback Shift Register Generator

The GFSR generator uses the recursion Xt = Xt-1563 ⊕ Xt-96. This generator, which is different from earlier GFSR generators, was proposed by Fushimi (1990), who discusses the theory behind the generator and reports on several empirical tests of it. Background discussions on this type of generator can be found in Kennedy and Gentle (1980), pages 150-162.

Setting Seed

The seed of the generator can be set and retrieved using IMSL_RANDOMOPT. Prior to invoking any generator in this section, you can call IMSL_RANDOMOPT to initialize the seed, which is an integer variable with a value between 1 and 2147483647. If it is not initialized by IMSL_RANDOMOPT, a random seed is obtained from the system clock. Once it is initialized, the seed need not be set again.

To restart a simulation, IMSL_RANDOMOPT can be used to obtain the final seed value of one run to be used as the starting value in a subsequent run. Also, if two simultaneous random number streams are desired in one run, IMSL_RANDOMOPT can be used before and after the invocations of the generators in each stream.

If a shuffled generator or the GFSR generator is used, in addition to resetting the seed, you must also reset some values in a table. For the shuffled generators, this is done using the routine IMSL_RANDOM_TABLE. The tables for the shuffled generators are separate for single and double precision; so, if precisions are mixed in a program, it is necessary to manage each precision separately for the shuffled generators.

Distributions Other than Uniform

The nonuniform generators use a variety of transformation procedures. All of the transformations used are exact (mathematically). The most straightforward transformation is the inverse CDF technique, but it is often less efficient than others involving acceptance/rejection and mixtures. See Kennedy and Gentle (1980) for discussion of these and other techniques.

Many of the nonuniform generators in this chapter use different algorithms depending on the values of the parameters of the distributions. This is particularly true of the generators for discrete distributions. Schmeiser (1983) gives an overview of techniques for generating deviates from discrete distributions.

Although, as noted above, the uniform generators yield the same sequences on different computers, because of rounding, the nonuniform generators that use acceptance/rejection may occasionally produce different sequences on different computer/compiler environments.

Although the generators for nonuniform distributions use fast algorithms, if a very large number of deviates from a fixed distribution are to be generated, it might be worthwhile to consider a table sampling method, as implemented in the routines IMSL_RAND_GEN_CONT and IMSL_RAND_GEN_DISCR.

Additional Notes on Syntax

The generators for continuous distributions are available in both single and double precision versions. This is merely for your convenience; the double precision versions should not be considered more “accurate,” except possibly for the multivariate distributions.



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