Guardian Native C Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)
mrand48(3) Guardian Native C Library Calls Reference Manual
NAME
mrand48 - 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 and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcrtldll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycrtldll
SYNOPSIS
#include <stdlib.h>
long mrand48(void);
DESCRIPTION
This function generates a sequence of pseudorandom numbers using the linear congruential algo-
rithm and 48-bit integer arithmetic.
The mrand48() function returns signed long integers uniformly distributed over the range of y
values such that -2 to the power 31 is less than or equal to y which is less than 2 to the power 31.
The srand48(), seed48(), and lcong48() functions initialize the random-number generator. Pro-
grams should invoke one of them before calling the *Lmrand48( ) function. (Although it is not
recommended practice, constant default initializer values are supplied automatically if the
mrand48() function is called without first calling an initialization function.)
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 mrand48() function is computed by first 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-significant) bits of X
i
and transformed into the returned value.
The mrand48() function stores the last 48-bit X
i
generated into an internal buffer, which is why
it must be initialized prior to being invoked.
NOTES
Prior to calling a random-number generator function, the init field of the struct drand48_data
structure (passed to the random-number generator functions) must be cleared.
This function supports both IEEE Std 754-1985 floating-point and Tandem floating-point values
in the native environment. IEEE values can include NaN and infinity, 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.
Guardian functions are available to convert between floating-point formats. Refer to the Guar-
dian Programmer’s Guide for a discussion of floating-point conversions.
4−116 Hewlett-Packard Company 527192-018