seed48() — 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>
unsigned short int *seed48(unsigned short int seed16v[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 lcong48(), seed48(), and srand48() functions are initialization functions, one of which should be invoked before either the drand48(), lrand48() or mrand48() function is called.
X(n+1) = (aX(n) + c)mod(2**48) n>=0 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 seed48() function is used to reinitialize the most recent 48-bit value in this storage. The seed48() function replaces the low-order (rightmost) 16 bits of this storage with seed16v[0], the middle-order 16 bits with seed16v[1], and the high-order 16 bits with seed16v[2].
The values a and c, may be changed by calling the lcong48() function. The seed48() function restores the initial values of a and c.
Special
behavior for z/OS® UNIX Services: You
can make the seed48() 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.
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>=0C/370 provides thread-specific
storage to save the most recent 48-bit integer value of the sequence,
X(t,i). When the seed48()function is called from thread t,
it reinitializes the most recent 48-bit value in this storage. The
seed48() function replaces the low-order (rightmost) 16 bits of this
storage with seed16v[0], the middle-order
16 bits with seed16v[1], and the high-order
16 bits with seed16v[2].
t. When the seed48()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
When seed48() is called, it saves the most recent 48-bit integer value in the sequence, X(i), in an array of unsigned short ints provided by C/370 before reinitializing storage for the most recent value in the sequence, X(i). seed48() returns a pointer to the array containing the saved value.
Special behavior
for z/OS UNIX Services: If
thread-specific behavior is requested for the drand48 family and seed48()
is called on thread t, it saves the most recent 48-bit
integer value in the sequence, X(t,i), for the thread in a thread-specific
array of unsigned short ints before reinitializing storage for the
most recent value in the sequence, X(t,i). seed48() returns a pointer
to this thread-specific array containing the saved value.
Related information
- stdlib.h — Standard library functions
- drand48() — Pseudo-random number generator
- erand48() — Pseudo-random number generator
- jrand48() — Pseudo-random number generator
- lcong48() — Pseudo-random number initializer
- lrand48() — Pseudo-random number generator
- mrand48() — Pseudo-random number generator
- nrand48() — Pseudo-random number generator
- srand48() — Pseudo-random number initializer