RUNIF(3)

SYNOPSIS
FUNCTION RUNIF (T, N)

NAME
runif - Generate a uniformly distributed random number.

LIBRARY
SLATEC (FNLIB)

CATEGORY
L6A21

TYPE
SINGLE PRECISION (RUNIF-S)

KEYWORDS
FNLIB, RANDOM NUMBER, SPECIAL FUNCTIONS, UNIFORM

AUTHOR
Fullerton, W., (LANL)

DESCRIPTION
This random number generator is portable among a wide variety of computers. It generates a random number between 0.0 and 1.0 accord- ing to the algorithm presented by Bays and Durham (TOMS, 2, 59, 1976). The motivation for using this scheme, which resembles the Maclaren-Marsaglia method, is to greatly increase the period of the random sequence. If the period of the basic generator (RAND) is P, then the expected mean period of the sequence generated by RUNIF is given by new mean P = SQRT (PI*FACTORIAL(N)/(8*P)), where FACTORIAL(N) must be much greater than P in this asymptotic formula. Generally, N should be around 32 if P=4.E6 as for RAND. Input Argument -- N ABS(N) is the number of random numbers in an auxiliary table. Note though that ABS(N)+1 is the number of items in array T. If N is positive and differs from its value in the previous invocation, then the table is initialized for the new value of N. If N is negative, ABS(N) is the number of items in an auxiliary table, but the tables are now assumed already to be initialized. This option enables the user to save the table T at the end of a long computer run and to restart with the same sequence. Normally, RUNIF would be called at most once with negative N. Subsequent invocations would have N positive and of the correct magnitude. Input and Output Argument -- T an array of ABS(N)+1 random numbers from a previous invocation of RUNIF. Whenever N is positive and differs from the old N, the table is initialized. The first ABS(N) numbers are the table discussed in the reference, and the N+1 -st value is Y. This array may be saved in order to restart a sequence. Output Value -- RUNIF a random number between 0.0 and 1.0.

REFERENCES
(NONE)

ROUTINES CALLED
RAND

REVISION HISTORY (YYMMDD)
770401 DATE WRITTEN
890531 Changed all specific intrinsics to generic. (WRB)
890531 REVISION DATE from Version 3.2
891214 Prologue converted to Version 4.0 format. (BAB)
910819 Added EXTERNAL statement for RAND due to problem on IBM RS 6000. (WRB)