RAN(3I) Last changed: 1-6-98
NAME _ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers
SYNOPSIS C/C++:
#include double _ranf(void);
Fortran:
RANF()
RANGET ([I=]i)
RANSET ([K=]k)
Fortran on UNICOS/mk systems only:
RANSET ([K=]k [, [J=]j]) RAN(3I) Last changed: 1-6-98
NAME _ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers
SYNOPSIS C/C++:
#include double _ranf(void);
Fortran:
RANF()
RANGET ([I=]i)
RANSET ([K=]k)
Fortran on UNICOS/mk systems only:
RANSET ([K=]k [, [J=]j]) RAN(3I) Last changed: 1-6-98
NAME _ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers
SYNOPSIS C/C++:
#include double _ranf(void);
Fortran:
RANF()
RANGET ([I=]i)
RANSET ([K=]k)
Fortran on UNICOS/mk systems only:
RANSET ([K=]k [, [J=]j]) RAN(3I) Last changed: 1-6-98
NAME _ranf, RANF, RANGET, RANSET - Computes pseudo-random numbers
SYNOPSIS C/C++:
#include double _ranf(void);
Fortran:
RANF()
RANGET ([I=]i)
RANSET ([K=]k)
Fortran on UNICOS/mk systems only:
RANSET ([K=]k [, [J=]j])
FORTRAN NOTES RANF obtains the first or next in a series of pseudo-random numbers. Parenthesis are required, that is: var = RANF(). If an argument is supplied, it is ignored.
The RANGET intrinsic function obtains a seed. It can be called as a function or a subroutine; it is recommended that this routine be used as a function. RANGET has an optional integer argument. If present, the argument is set to the seed. The argument for RANGET is as follows:
i An integer of default kind (KIND=8). If present, RANGET returns the seed in i.
On UNICOS and UNICOS/mk systems, the RANSET intrinsic function establishes a seed by using the lower 48 bits of the argument. The result type is typeless. If no argument or a zero argument is supplied, the seed is reset to an initial default value. When the seed of the random number generator is reset, RANSET does not store the supplied argument as the first value in the buffer of the random number seeds. If an argument is supplied, the lower 48 bits are used as the random-number seed. The rightmost bit is always set to 1.
The RANSET arguments are as follows:
k An optional integer, real, or Boolean argument of default kind (KIND=8) The range of argument k is |k| < inf, where inf is as follows: 2450 * On UNICOS systems, infinity is approximately 10 . 308 * On UNICOS/mk and IRIX systems, infinity is approximately 10 .
j An optional integer argument that, if specified, is used as a count for skipping the first section of sequential random numbers. You can use this to create a complete sequence of random numbers while running on many PEs by breaking up the sequence into subsequences and using RANSET() to get each subsequence started in the correct location.
The names of these intrinsics cannot be passed as arguments.
THE RANF ALGORITHM In Fortran on CRAY C90 systems, the random number generation algorithm uses the following two equations:
* S(n+1) = M1*S(n) mod 2**48
* S(n+64) = M64*S(n) mod 2**48
Each S(i) is the ith seed.
The first equation is used to generate the first 128 random numbers and store them in a table if a call to RANSET() was done. Otherwise, the table contains the first 128 random numbers from the default seed. The second equation is used because it vectorizes.
The default seed is S(0) = 1274321477413155 (octal).
The operations M1*S(n) and M64*S(n) are done as integer multiplications in such a way to preserve the lower 48 bits. It is the lower 48 bits that make the next random number seed and are used in the return value.
The return value (random number) is the newly generated seed with an exponent of 40000 (octal) added. This is normalized before exit.
The multiplier M1 is 1207264271730565 (octal) and is related to M64 by the following expression: M64 = lower 48 bits of M1**64 = 7027423346125401 (octal).
For example, the following Fortran program, when compiled with the f90 -i 64 option on a CRAY C90 system, is the equivalent of the RANF function:
cc c THIS IS A FORTRAN VERSION OF RANF() FUNCTION cc REAL FUNCTION RANF() REAL NORM INTEGER MHI,MLO,EXPO,SEED,SEEDHI,SEEDLO DATA SEED/1274321477413155B/ SAVE SEED
MHI = 12072642B MLO = 71730565B
EXPO = SHIFTL(40000B,48)
SEEDHI = SHIFTR(AND(SHIFTL(77777777B,24),SEED),24) SEEDLO = AND(77777777B,SEED)
SEED = AND(7777777777777777B,SEEDLO*MLO+ 1 SHIFTL(SEEDLO*MHI+SEEDHI*MLO,24))
RANF=NORM(OR(EXPO,SEED),0.0) RETURN END cc c THIS IS HERE TO NORMALIZE THE FLOATING POINT RESULT cc REAL FUNCTION NORM(X,Y) REAL X,Y NORM = X+Y RETURN END
On IRIX systems, RANF uses a 64-bit linear congruential generator with a default seed of 1274321477413155 (octal).
THE RANF REPEAT PERIOD In Fortran, the period of RANF() is 2**46. If you need to insure that two random number ranges do not overlap, you can determine this empirically by generating the two sets of numbers and comparing them against one another, and also against themselves, for an overlap. It should be noted, however, that when using RANSET to set the random number seed, the algorithm used always rounds up even-numbered seeds to the nearest odd-numbered seed (that is, the right most bit is always set to one). Some adjacent pairs of seeds will generate exactly the same set of random numbers. For example, seeds 4 and 5 will generate the same set of random numbers.
RANF AND MULTITASKING In Fortran, the random number generator uses static memory storage for the random number seed table, so the RANF, RANSET, and RANGET functions must be protected (locked) when called from a multitasked program.
RANF generates a set of random numbers such that each random number depends on the previous random number for its value. Thus, depending on the order in which the tasks calling RANF execute, a different set of random numbers will be returned to each task. It cannot be guaranteed that each task will get a distinct and reproducible set of random number values.
RETURN VALUES _ranf and RANF return a 64-bit floating-point number in the range 0.0 < x < 1.0.
RANGET returns a 64-bit integer result.
RANSET returns a 64-bit typeless result.
EXAMPLES The following examples are written in Fortran:
DO 10 I=1,10 10 RANDOM(I)=RANF()
CALL RANGET(iseed1) C or iseed=RANGET(ivalue)
CALL RANSET(ivalue) C or dummy=RANSET(ivalue)
SEE ALSO RANDOM_NUMBER(3I), RANDOM_SEED(3I)
rand(3C) in the UNICOS System Libraries Reference Manual, publication SR-2080
A complete list of C/C++ intrinsic functions available on Cray Research systems is in the Cray C/C++ Reference Manual, publication SR -2179.
Intrinsic Procedures Reference Manual, publication SR-2138, for the printed version of this man page.
|