Guardian Native C Library Calls Reference Manual (G06.28+, H06.04+)

Guardian Native C Library Calls (n - r) nrand48(3)
NAME
nrand48 - Generates uniformly distributed pseudorandom number sequences
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
H-series OSS processes: /G/system/zdllnnn/zcrtldll
SYNOPSIS
#include <stdlib.h>
long nrand48(
unsigned short xsubi[3]);
PARAMETERS
xsubi Species an array of three short integers, which, when concatenated together,
form a 48-bit integer.
DESCRIPTION
This function generates a sequence of pseudorandom numbers using the linear congruential algo-
rithm and 48-bit integer arithmetic.
The nrand48( ) function returns nonnegative long integers uniformly distributed over the range
of y values such that 0.0 (zero) is less than or equal to y which is less than 2 to the power 31.
The nrand48( ) function does not require that an initialization function be called rst.
The function generates a sequence of 48-bit integer values, X
i
, according to the linear congruen-
tial formula:
X
n+1
= (aX
n
+c)
mod m
n 0
The value of m equals 2 to the power 48; hence 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 values returned by the nrand48( ) function is computed by rst generating the next 48-bit X
i
in the sequence. Then the appropriate bits, according to the type of data item to be returned, are
copied from the high-order (most-signicant) bits of X
i
and transformed into the returned value.
The nrand48( ) function requires that the calling program provide storage for the successive X
i
values in the array pointed to by the xsubi parameter. This is why this routine does 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 nrand48() function allow sseparate modules of a large pro-
gram to generate several independent sequences of pseudorandom numbers; that is, the sequence
of numbers that one module generates does not depend upon how many times the functions are
called by other modules.
NOTES
Prior to calling a random-number generator function, the init eld of the struct drand48_data
structure (passed to the random-number generator functions) must be cleared.
This function supports both IEEE Std 754-1985 oating-point and Tandem oating-point values
in the native environment. IEEE values can include NaN and innity, and the sign of 0.0 (zero)
can be either positive or negative. Refer to the fp_class(3) reference page for a description of
IEEE value classes.
527192-005 Hewlett-Packard Company 55