erand48() — Pseudo-random number generator

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE
#include <stdlib.h>

double erand48(unsigned short int x16v[3]);

General description

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). These functions have been extended so that the returned value will be in the proper floating-point format (hexadecimal or IEEE) based on the floating-point mode of the invoking thread.

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).

The erand48() function generates the next 48-bit integer value in a sequence of 48-bit integer values, X(i), according to the linear congruential formula:
X(n+1) = (aX(n) + c)mod(2**48)     n>=0

The erand48() 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 erand48() 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.

The initial values of a, and c are:
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 erand48() 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.

If thread-specific behavior is requested and the erand48() function is called from thread t, the erand48() function generates the next 48-bit integer value in a sequence of 48-bit integer values, X(t,i), for the thread according to the linear congruential formula:
X(t,n+1) = (a(t)X(t,n) + c(t))mod(2**48)     n>=0

The erand48() 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 erand48() 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.

The initial values of a(t) and c(t) on the thread t are:
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.

Returned value

erand48() saves the generated 48-bit value, X(n+1), in storage provided by the argument array, x16v[3]. erand48() transforms the generated 48-bit value to a double-precision, floating-point value on the interval [0.0,1.0) and returns this transformed value.

Special behavior for z/OS UNIX Services: If thread-specific behavior is requested for the drand48 family and erand48() is called on thread t, erand48() saves the generated 48-bit value, X(t,n+1), in storage provided by the argument array, x16v[3]. erand48() transforms the generated 48-bit value to a double-precision, floating-point value on the interval [0.0,1.0) and returns this transformed value.

Related information