DRAND48(3,L) AIX Technical Reference DRAND48(3,L)
-------------------------------------------------------------------------------
drand48
PURPOSE
Generates uniformly distributed pseudo-random number sequences.
LIBRARY
Standard C Library (libc.a)
SYNTAX
double drand48 ( ) long jrand48 (xsubi)
unsigned short xsubi[3];
double erand48 (xsubi)
unsigned short xsubi[3]; void srand48 (seedval)
long seedval;
long lrand48 ( )
unsigned short *seed48 (seed16v)
long nrand48 (xsubi) unsigned short seed16v[3];
unsigned short xsubi[3];
void lcong48 (param)
long mrand48 ( ); unsigned short param[7];
DESCRIPTION
This family of subroutines generates pseudo-random numbers using the linear
congruential algorithm and 48-bit integer arithmetic.
The drand48 and erand48 subroutines return nonnegative double-precision
floating-point values uniformly distributed over the range of y values such
that 0.0 <= y < 1.0.
The lrand48 and nrand48 subroutines return nonnegative long integers uniformly
distributed over the range of y values such that 0 <= y < 2(31).
The mrand48 and jrand48 subroutines return signed long integers uniformly
distributed over the range of y values such that -2(31) <= y < 2(31).
The srand48, seed48 and lcong48 subroutines initialize the random-number
generator. Programs should invoke one of them before calling drand48, lrand48
or mrand48. (Although it is not recommended practice, constant default
initializer values are supplied automatically if the drand48, lrand48 or
mrand48 subroutines are called without first calling an initialization
Processed November 7, 1990 DRAND48(3,L) 1
DRAND48(3,L) AIX Technical Reference DRAND48(3,L)
subroutine.) The erand48, nrand48 and jrand48 subroutines do not require that
an initialization subroutine to be called first.
All the subroutines work by generating a sequence of 48-bit integer values,
X[i], according to the linear congruential formula:
X sub = (aX sub n + c) sub %%%% n ge 0
The parameter m = 2(48); hence 48-bit integer arithmetic is performed. Unless
the lcong48 subroutine has been called, the multiplier value a and the addend
value c are:
a = '5DEECE66D' sub 16 = '273673163155' sub 8
c = 'B' sub 16 = '13' sub 8
The value returned by the drand48, erand48, lrand48, nrand48, mrand48, and
jrand48 subroutines is computed by first generating the next 48-bit X[i] in the
sequence. Then the appropriate number of bits, according to the type of data
item to be returned, are copied from the high-order (most significant) bits of
X[i] and transformed into the returned value.
The drand48, lrand48 and mrand48 subroutines store the last 48-bit X[i]
generated into an internal buffer; that is why they must be initialized prior
to being invoked.
The erand48, nrand48 and jrand48 subroutines require the calling program to
provide storage for the successive X[i] values in the array pointed to by the
xsubi parameter. That is why these routines do not have to be initialized; the
calling program merely has to place the desired initial value of X[i] into the
array and pass it as a parameter.
By using different parameters, the erand48, nrand48, and jrand48 subroutines
allow separate modules of a large program to generate several independent
sequences of pseudo-random numbers. In other words, the sequence of numbers
that one module generates does not depend upon how many times the subroutines
are called by other modules.
The initializer subroutine srand48 sets the high-order 32 bits of X[i] to the
32 bits contained in its parameter. The low order 16 bits of X[i] are set to
the arbitrary value 330E[16].
The initializer subroutine seed48 sets the value of X[i] to the 48-bit value
specified in the array pointed to by the seed16v parameter. In addition,
seed48 returns a pointer to a 48-bit internal buffer that contains the previous
value of X[i]. that is used only by seed48. The returned pointer allows you
to restart the pseudo-random sequence at a given point. Use the pointer to
copy the previous X[i] value into a temporary array. Later you can call seed48
with a pointer to this array to resume where the original sequence left off.
The lcong48 subroutine specifies the initial X[i] value, the multiplier value
a, and the addend value c. The parameter array elements param[0-2] specify
Processed November 7, 1990 DRAND48(3,L) 2
DRAND48(3,L) AIX Technical Reference DRAND48(3,L)
X[i], param[3-5] specify the multiplier a, and param[6] specifies the 16-bit
addend c. After lcong48 has been called, a subsequent call to either srand48
or seed48 restores the standard a and c as specified previously.
RELATED INFORMATION
In this book: "rand, srand."
Processed November 7, 1990 DRAND48(3,L) 3