Usage Notes¶
Statistics¶
The functions in this section can be used to compute some common univariate summary statistics, perform a one-sample goodness-of-fit test, produce measures of correlation, perform multiple and polynomial regression analysis, and compute ranks (or a transformation of the ranks, such as normal or exponential scores). See the IMSL C Stat Library for a more extensive collection of statistical functions and detailed descriptions.
Overview of Random Number Generation¶
“Random Numbers” describes functions for the generation of random numbers and of random samples and permutations. These functions are useful for applications in Monte Carlo or simulation studies. Before using any of the random number generators, the generator must be initialized by selecting a seed or starting value. This can be done by calling the function randomSeedSet. If the user does 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. There are other utility functions in this chapter for selecting the form of the basic generator, for restarting simulations, and for maintaining separate simulation streams.
In the following discussions, the phrases “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 completely deterministic and repeatable, they simulate the realizations of independent and identically distributed random variables.
The Basic Uniform Generator¶
The random number generators in this chapter use a multiplicative congruential method. The form of the generator is
Each \(x_i\) is then scaled into the unit interval (0,1). If the multiplier, c, is a primitive root modulo \(2^{31}-1\) (which is a prime), then the generator will have a maximal period of \(2^{31}-2\). There are several other considerations, however. See Knuth (1981) for a good general discussion. The possible values for c in the IMSL generators are 16807, 397204094, and 950706376. The selection is made by the function randomOption. 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).
The generation of uniform (0,1) numbers is done by the function randomUniform. This function is portable in the sense that, given the same seed, it produces the same sequence in all computer/compiler environments.
Shuffled Generators¶
The user also can select a shuffled version of these generators using randomOption. 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 \(x_i\) from the simple generator, the low-order bits of \(x_i\) 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 \(x_i\), 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.
Setting the Seed¶
The seed of the generator can be set in randomSeedSet and can be retrieved by randomSeedGet. Prior to invoking any generator in this section, the user can call randomSeedSet to initialize the seed, which is an integer variable with a value between 1 and 2147483647. If it is not initialized by randomSeedSet, a random seed is obtained from the system clock. Once it is initialized, the seed need not be set again.
If the user wishes to restart a simulation, by randomSeedGet 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, randomSeedSet and by randomSeedGet can be used before and after the invocations of the generators in each stream.