Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4 |
both |
#define _XOPEN_SOURCE
#include <stdlib.h>
long int nrand48(unsigned short int x16v[3]);
The drand48(), erand48(), jrand48(), lrand48(), mrand48() and nrand48() functions generate uniformly distributed pseudo-random numbers using a linear congruential algorithm and 48-bit integer arithmetic.
The functions drand48() and erand48() return nonnegative, double-precision, floating-point values, uniformly distributed over the interval [0.0,1.0).
The functions lrand48() and nrand48() return nonnegative, long integers, uniformly distributed over the interval [0,2**31).
The functions mrand48() and jrand48() return signed long integers, uniformly distributed over the interval [-2**31,2**31).
X(n+1) = (aX(n) + c)mod(2**48) n>=0
The nrand48() function uses storage provided by the argument array, x16v[3], to save the most recent 48-bit integer value in the sequence, X(i). The nrand48() function uses x16v[0] for the low-order (rightmost) 16 bits, x16v[1] for the middle-order 16 bits, and x16v[2] for the high-order 16 bits of this value.
a = 5deece66d (base 16)
c = b (base 16)
The values a and c, may be changed by calling the lcong48() function. The initial values of a and c are restored if either the seed48() or srand48() function is called.
Special behavior for z/OS® UNIX Services: You can make the nrand48() function and other functions in the drand48 family thread-specific by setting the environment variable _RAND48 to the value THREAD before calling any function in the drand48 family.
If you do not request thread-specific behavior for the drand48 family, C/370™ serializes access to the storage for X(n), a and c by functions in the drand48 family when they are called by a multithreaded application.
X(t,n+1) = (a(t)X(t,n) + c(t))mod(2**48) n>=0
The nrand48() function uses storage provided by the argument array, x16v[3], to save the most recent 48-bit integer value in the sequence, X(t,i). The nrand48() function uses x16v[0] for the low-order (rightmost) 16 bits, x16v[1] for the middle-order 16 bits, and x16v[2] for the high-order 16 bits of this value.
a(t) = 5deece66d (base 16)
c(t) = b (base 16)
The values a(t) and c(t) may be changed by calling the lcong48() function from the thread t. The initial values of a(t) and c(t) are restored if either the seed48() or srand48() function is called from the thread.
nrand48() saves the generated 48-bit value, X(n+1), in storage provided by the argument array, x16v[3]. nrand48() transforms the generated 48-bit value to a nonnegative, long integer value on the interval [0,2**31) and returns this transformed value.
Special behavior for z/OS UNIX Services: If thread-specific behavior is requested for the drand48 family and nrand48() is called on thread t, nrand48() saves the generated 48-bit value, X(t,n+1), in storage provided by the argument array, x16v[3]. nrand48() transforms the generated 48-bit value to a nonnegative, long integer value on the interval [0,2**31) and returns this transformed value.