HP C/iX Library Reference Manual (30026-90004)

Chapter 5 287
HP C/iX Library Function Descriptions
rand48
Return Values
x Random numbers appropriate to the type and function called (except
seed
,
which returns a pointer to the internal buffer where X is stored).
Description
This family of functions generates uniform pseudo-random numbers using the linear
congruential algorithm and 48-bit integer arithmetic.
The drand48 and erand48 functions return non-negative double-precision floating-point
values uniformly distributed over the interval of 0.0 (inclusive) to 1.0 (non-inclusive) or, in
mathematical nomenclature, (0.0,1.0).
The lrand48 and nrand48 functions return non-negative long integers uniformly
distributed over the interval of 0 (inclusive) to 2
31
(non-inclusive), or (0, 2
31
).
The mrand48 and jrand48 functions return signed long integers uniformly distributed
over the interval of -2
31
(inclusive) to 2
31
(non-inclusive), or (-2
31
, 2
31
).
The srand48, seed48 and lcong48 functions are initialization entry points, one of which
should be invoked before either drand48, lrand48 or mrand48 is called. Although it is not
recommended practice, constant default initializer values are supplied automatically if
drand48, lrand48 or mrand48 is called without a prior call to an initialization entry point.
The erand48, nrand48, and jrand48 functions do not require an initialization entry point
to be called first.
All the functions work by generating a sequence of 48-bit integer values,
X
i
, according to
the linear congruential formula:
X
n+1
= (
aX
n
+
c)
mod m
n
0.
The parameter
m = 2
48
; therefore 48-bit integer arithmetic is performed. Unless lcong48
has been invoked, the multiplier value
a
and the addend value
c
are given by:
a
= 5DEECE66D
16
= 273673163155
8
c
= B
16
= 13
8
The value returned by drand48, erand48, lrand48, nrand48, mrand48 or jrand48 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 (leftmost) bits of
X
i
and transformed into the returned value.
The drand48, lrand48 and mrand48 functions store the last 48-bit
X
i
generated in an
internal buffer, which is why they must be initialized prior to being invoked. The erand48,
nrand48 and jrand48 functions require the calling program to provide storage for the
successive
X
i
values in the array specified as an argument when the functions are invoked.
That is why these functions 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 an argument. By using
different arguments, the erand48, nrand48 and jrand48 functions allow separate modules
of a large program to generate several independent streams of pseudo-random numbers.
For example, the sequence of numbers in each stream does not depend upon how many