| |
Random Number Generators
This document indexes the various pseudo-random number generators
available on NERSC computers. The systems are covered individually and in
combinations. Further information about the software listed here
may be available as man pages on the target systems.
Some of the available generators can be used in parallel programs, but
special considerations apply to such use, see
A Brief on Parallel Random Number
Generators.
Except where specifically indicated, the
routines named have not been tested. Similar names on different platforms do
not guarantee similar generators or output sequences. Repeatable behavior
between runs or in parallel usage, may or may not be possible. Even in the
case of identical generators, differences between platforms may arise, due to
differences in arithmetic, operand lengths, and compiler options.
- pranf
-
The PRANF genarator suite provides the generator of SGI/Cray's
RANF function, along with a set of seed generation routines, in Fortran, using
radix-4096 (12-bit) integer calculations. This offers portability and
deterministic parallelism at the expense of performance. PRANF is intended
for use on shared memory systems. It has not yet been tested on the SP system
by NERSC staff. For more information, see The PRANF Portable
Parallel Random Number Generator.
- rand, srand (libc.a),
RAND (xlf intrinsic)
-
libc.a: The rand subroutine
generates a pseudo-random number using a multiplicative congruential algorithm.
The random-number generator has a period of 2**32, and it returns successive
pseudo-random numbers in the range from 0 through (2**15)-1. The
srand subroutine resets the
rand generator to a new starting
point. It uses the Seed parameter as a seed for a new sequence of pseudo-random
numbers to be returned by subsequent calls to the
rand subroutine. This version of these two
routines is from the standard C library, libc.a.
xlf: Another pair of routines named rand and
srand exist as disparaged intrinsics in
the Fortran compiler. Their functionality is approximately the same, but the
numbers generated are uniformly distributed greater than or equal to zero and
less then one. Use of these two routines is not recommended. The more modern
Fortran 90 intrinsics, RANDOM_NUMBER and
RANDOM_SEED are recommended instead.
- rand_r
Multithread-safe version of
rand, discussed above.
- random, srandom, initstate, setstate
Generates pseudo-random numbers more efficiently. The
random subroutine uses a non-linear
additive feedback random-number generator to return successive pseudo-random
numbers in the range from 0 to 2**31-1. The
random and
srandom subroutines have almost the same
calling sequence and initialization properties as the
rand and
srand subroutines. The difference is that
the rand subroutine produces a much less random sequence; the low dozen bits
generated by the rand subroutine go through a cyclic pattern, while all the
bits generated by the random subroutine
are usable. The initstate subroutine
allows a state array, passed in as an argument, to be initialized for future
use. The setstate subroutine allows rapid
switching between states.
- srandom_r, initstate_r, or setstate_r
Multithread-safe version of
random, srandom, initstate, setstate,
discussed above.
- drand48, erand48, jrand48, lcong48,
lrand48, mrand48, nrand48, seed48, srand48
Generate uniformly distributed pseudo-random number sequences.
This family of subroutines generates pseudo-random numbers using the linear
congruential algorithm and 48-bit integer arithmetic.
The drand48 and
erand48 subroutines return positive
double-precision floating-point values uniformly distributed over the interval
[0.0, 1.0). The lrand48 and
nrand48 subroutines return positive long
integers uniformly distributed over the interval [0,2**31). The
mrand48 and
jrand48 subroutines return signed long
integers uniformly distributed over the interval [-2**31, 2**31). The
srand48,
seed48, and
lcong48 subroutines initialize the
random-number generator. Programs must call one of them before calling the
drand48, lrand48 or mrand48 subroutines.
- erand48_r, lrand48_r, nrand48_r, mrand48_r,
jrand48_r, srand48_r
Multithread-safe versions of erand48,
lrand48, nrand48, mrand48, jrand48, srand48, discussed
above.
- RANDOM_NUMBER, RANDOM_SEED
The RANDOM_NUMBER Fortran 90
intrinsic subroutine returns one pseudorandom number or an array of
pseudorandom numbers from the uniform distribution over the range 0 <= x < 1.
The RANDOM_SEED Fortran 90 intrinsic
subroutine restarts or queries the pseudorandom number generator used by
RANDOM_NUMBER.
- SURAND, DURAND, SNRAND, DNRAND, SURXOR,
DURXOR
Subroutines SURAND and
DURAND generate vectors of uniformly
distributed random numbers, in short and long precision, respectively.
Subroutines SNRAND and
DNRAND generate vectors of normally
distributed random numbers, in short and long precision, respectively.
Subroutines SURXOR and
DURXOR generate vectors of long period
uniformly distributed random numbers, in short and long precision, respectively.
These routines are all part of the ESSL library. For more information,
the Random Numer Generation section of the
ESSL Guide and Reference.
- URNG, PDURNG
Subroutine URNG generates a vector of
uniform pseudo-random numbers in the ranges (0,1) or (-1,1), depending on an
argument. The random numbers are generated using the multiplicative
congruential method with a user-specified seed.
Subroutine PDURNG generates a global
vector of uniform pseudo-random numbers in the ranges (0,1) or (-1,1),
depending on an argument. The random numbers are generated using the
multiplicative congruential method with a user-specified seed. These routines
are all part of the PESSL library. For more information, see
the Random Numer Generation section of the
PESSL Guide and Reference.
- sprng
The Scalable Parallel Random Number Generators (SPRNG) library
provides a variety of generators and a "spawn" facility to generate new streams.
The user must select among the various generators, which include
- lcg - a 48-Bit Linear Congruential Generator with Prime Addend
- lcg64 - a 64-Bit Linear Congruential Generator with Prime Addend
- lfg - a Modified Lagged Fibonacci Generator
- mlcg - a Multiplicative Lagged Fibonacci Generator
- cmrg - a Combined Multiple Recursive Generator
It is available in its own
module; type "module load sprng" to make it
available. For more information, and to see the test code source with sample
parallel usage, see
Using SPRNG at NERSC.
Common Libraries
- NAG
Chapter G05 of the NAG web documentation contains over 40 routines for generating
and manipulating random numbers of many kinds and from many distributions.
The IBM SP has double precision version.
|