RAND48 48-bit Random Number Generators

RAND48 is a C library which demonstrates the use of several stdlib functions, which uses 48-bit arithmetic to generate uniformly distributed pseudorandom value. The results can be returned as double precision values in [0.0,1.0], or as long integers in [-2^31,2^31], or as nonnegative long integers in [0,2^31].

The underlying calculations are done in 48-bit integer arithmetic. The user has the option of allowing the system to select the initial seed, or of supplying 32 bits of the seed as a long int, or supplying all 48 bits of the seed as 3 16 bit values. The user can also supply the seed as an explicit argument on each call, or make a single initialization call with the desired seed.

Routines to set the seed:

• void srand48(long int seedval),
the user passes in a long int. The 32 bits of this value are used, along with 16 bits supplied internally. This is the most convenient routine to call.
• unsigned short int *seed48(unsigned short int seedvec),
the user passes in 3 16 bit values which completely determine the seed. This gives the user full control over the seed.
• void lcong48(unsigned short int param),
allows the user to specify the seed as in seed48, but also the 48 bit multiplier and 16 bit addend used in the linear congruential generator.

There are 3 routines available which return a random value, assuming that the seed has been set in advance by a call to srand48, seed48, or lcong48, or that the user is satisfied with a default seed value. These routines have no input argument.

• double drand48(void)
returns a double precision floating point value in [0.0,1.0];
• long int lrand48(void),
returns a nonnegative long integer in [0,2^31];
• long int mrand48(void),
returns a long integer in [-2^31,2^31];

There are 3 routines available which return a random value, whose computation is determined by the value of the seed vector in the input argument. These routines do not require the user to call a seed initialization routine first.

• double erand48(unsigned short int seedvec)
returns a double precision floating point value in [0.0,1.0];
• long int nrand48(unsigned short int seedvec),
returns a nonnegative long integer in [0,2^31];
• long int jrand48(unsigned short int seedvec),
returns a long integer in [-2^31,2^31];

Languages:

RAND48 is available in a C version and a C++ version.

Related Data and Programs:

ASA183, a C library which implements the Wichman-Hill pseudorandom number generator.

C_RANDOM, C programs which illustrate the use of C's random number generator routines.

FAURE, a C++ library which computes elements of a Faure quasirandom sequence.

HALTON, a C++ library which computes elements of a Halton quasirandom sequence.

HAMMERSLEY, a C++ library which computes elements of a Hammersley quasirandom sequence.

NIEDERREITER2, a C++ library which computes elements of a Niederreiter sequence using base 2.

NORMAL, a C library which computes elements of a sequence of pseudorandom normally distributed values.

RANLIB, a C library which produces random samples from Probability Density Functions (PDF's), including Beta, Chi-square Exponential, F, Gamma, Multivariate normal, Noncentral chi-square, Noncentral F, Univariate normal, random permutations, Real uniform, Binomial, Negative Binomial, Multinomial, Poisson and Integer uniform, by Barry Brown and James Lovato.

SOBOL, a C++ library which computes elements of a Sobol quasirandom sequence.

UNIFORM, a C library which computes elements of a sequence of pseudorandom uniformly distributed values.

VAN_DER_CORPUT, a C++ library which computes elements of a 1D van der Corput sequence.

Reference:

1. Donald Knuth,
The Art of Computer Programming,
Volume 2, Seminumerical Algorithms,
Third Edition,