Manpage of DRAND48
DRAND48
Section: Linux Programmer's Manual (3)Updated: 20170915
Index
NAME
drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48  generate uniformly distributed pseudorandom numbersSYNOPSIS
#include <stdlib.h>double drand48(void);double erand48(unsigned short xsubi[3]);long int lrand48(void);long int nrand48(unsigned short xsubi[3]);long int mrand48(void);long int jrand48(unsigned short xsubi[3]);void srand48(long int seedval);unsigned short *seed48(unsigned short seed16v[3]);void lcong48(unsigned short param[7]);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
All functions shown above:
_XOPEN_SOURCE
 /* Glibc since 2.19: */ _DEFAULT_SOURCE
 /* Glibc versions <= 2.19: */ _SVID_SOURCE
DESCRIPTION
These functions generate pseudorandom numbers using the linear congruential algorithm and 48bit integer arithmetic.The drand48() and erand48() functions return nonnegative doubleprecision floatingpoint values uniformly distributed over the interval [0.0, 1.0).
The lrand48() and nrand48() functions return nonnegative long integers uniformly distributed over the interval [0, 2^31).
The mrand48() and jrand48() functions return signed long integers uniformly distributed over the interval [2^31, 2^31).
The srand48(), seed48() and lcong48() functions are initialization functions, one of which should be called before using drand48(), lrand48() or mrand48(). The functions erand48(), nrand48() and jrand48() do not require an initialization function to be called first.
All the functions work by generating a sequence of 48bit integers, Xi, according to the linear congruential formula:
Xn+1 = (aXn + c) mod m, where n >= 0
The parameter m= 2^48, hence 48bit integer arithmetic is performed. Unless lcong48() is called, aand care given by:
a = 0x5DEECE66Dc = 0xB
The value returned by any of the functions drand48(), erand48(), lrand48(), nrand48(), mrand48() or jrand48() is computed by first generating the
48bit Xiin the sequence. Then the appropriate number of bits, according to the type of data item to be returned, is copied from the highorder bits of Xiand transformed into the returned value.The functions drand48(), lrand48() and mrand48() store the last 48bit Xigenerated in an internal buffer. The functions erand48(), nrand48() and jrand48() require the calling program to provide storage for the successive Xivalues in the array argument xsubi. The functions are initialized by placing the initial value of Xiinto the array before calling the function for the first time.
The initializer function srand48() sets the high order 32bits of Xito the argument seedval. The low order 16bits are set to the arbitrary value 0x330E.
The initializer function seed48() sets the value of Xito the 48bit value specified in the array argument seed16v. The
value of Xiis copied into an internal buffer and a pointer to this buffer is returned by seed48().The initialization function lcong48() allows the user to specify initial values for Xi, aand c. Array argument elements param[02]specify Xi, param[35]specify a, and param[6]specifies c. After lcong48() has been called, a subsequent call to either srand48() or seed48() will restore the standard values of aand c.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).Interface  Attribute  Value 
drand48(), erand48(), lrand48(), nrand48(), mrand48(), jrand48(), srand48(), seed48(), lcong48()  Thread safety  MTUnsafe race:drand48

The above functions record global state information for the random number generator, so they are not threadsafe.
CONFORMING TO
POSIX.12001, POSIX.12008, SVr4.SEE ALSO
rand(3), random(3)Index
This document was created by man2html, using the manual pages.
Time: 19:53:49 GMT, October 26, 2017 Click Here!