srand48() — Pseudo-random number initializer

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE
#include <stdlib.h>

void srand48(long int seedval);

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 lcong48(), seed48(), and srand48() functions are initialization functions, one of which should be invoked before either the drand48(), lrand48() or mrand48() function is called.

The drand48(), lrand48() and mrand48() functions generate 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 initial values of X, a, and c are:
   X(0)= 1
   a   = 5deece66d (base 16)
   c   = b         (base 16)

C/370™ provides storage to save the most recent 48-bit integer value of the sequence, X(i). This storage is shared by the drand48(), lrand48() and mrand48() functions. The srand48() function is used to reinitialize the most recent 48-bit value in this storage. The srand48() function replaces the high-order (leftmost) 32 bits of this storage with seedval argument value. The srand48() function replaces the low-order 16 bits of this storage with the value 330E (base 16).

The values a and c, may be changed by calling the lcong48() function. The srand48()function restores the initial values of a and c.

Special behavior for z/OS® UNIX Services: You can make the srand48() 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, calls to the drand48(), lrand48() and mrand48() functions from thread t generate a sequence of 48-bit integer values, X(t,i), according to the linear congruential formula:
   X(t,n+1) = (a(t)X(t,n) + c(t))mod(2**48)     n>=0

C/370 provides thread-specific storage to save the most recent 48-bit integer value of the sequence, X(t,i). When the srand48()function is called from thread t, it reinitializes the most recent 48-bit value in this storage. The srand48() function replaces the high-order (leftmost) 32 bits of this storage with seedval argument value. The srand48() function replaces the low-order 16 bits of this storage with the value 330E (base 16).

The values of a(t) and c(t) may be changed by calling the lcong48() function from thread t. When the srand48()function is called from this thread it restores the initial values of a(t) and c(t) for the thread which are:
   a(t)   = 5deece66d (base 16)
   c(t)   = b         (base 16)

Returned value

srand48() returns no values.

srand48() returns after it has used the value of the argument seedval to reinitialize storage for the most recent 48-bit integer value in the sequence, X(i), and has restored the initial values of a and c.

Special behavior for z/OS UNIX Services: If thread-specific behavior is requested for the drand48 family and the srand48() function is called on thread t, it uses the value of the argument seedval to reinitialize storage for the most recent 48-bit integer value in the sequence, X(t,i), for the thread. It also restores the initial values of a(t) and c(t) for the thread. Then it returns.

Related information