Provided by: manpages-dev_4.15-1_all

**NAME**

drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48 - generate uniformly distributed pseudo-random numbers

**SYNOPSIS**

#include<stdlib.h>doubledrand48(void);doubleerand48(unsignedshortxsubi[3]);longintlrand48(void);longintnrand48(unsignedshortxsubi[3]);longintmrand48(void);longintjrand48(unsignedshortxsubi[3]);voidsrand48(longintseedval);unsignedshort*seed48(unsignedshortseed16v[3]);voidlcong48(unsignedshortparam[7]);Feature Test Macro Requirements for glibc (seefeature_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 pseudo-random numbers using the linear congruential algorithm and 48-bit integer arithmetic. Thedrand48() anderand48() functions return nonnegative double-precision floating-point values uniformly distributed over the interval [0.0, 1.0). Thelrand48() andnrand48() functions return nonnegative long integers uniformly distributed over the interval [0, 2^31). Themrand48() andjrand48() functions return signed long integers uniformly distributed over the interval [-2^31, 2^31). Thesrand48(),seed48() andlcong48() functions are initialization functions, one of which should be called before usingdrand48(),lrand48() ormrand48(). The functionserand48(),nrand48() andjrand48() do not require an initialization function to be called first. All the functions work by generating a sequence of 48-bit integers,Xi, according to the linear congruential formula:Xn+1=(aXn+c)modm,wheren>=0The parameterm= 2^48, hence 48-bit integer arithmetic is performed. Unlesslcong48() is called,aandcare given by:a=0x5DEECE66Dc=0xBThe value returned by any of the functionsdrand48(),erand48(),lrand48(),nrand48(),mrand48() orjrand48() is computed by first generating the next 48-bitXiin the sequence. Then the appropriate number of bits, according to the type of data item to be returned, is copied from the high-order bits ofXiand transformed into the returned value. The functionsdrand48(),lrand48() andmrand48() store the last 48-bitXigenerated in an internal buffer. The functionserand48(),nrand48() andjrand48() require the calling program to provide storage for the successiveXivalues in the array argumentxsubi. The functions are initialized by placing the initial value ofXiinto the array before calling the function for the first time. The initializer functionsrand48() sets the high order 32-bits ofXito the argumentseedval. The low order 16-bits are set to the arbitrary value 0x330E. The initializer functionseed48() sets the value ofXito the 48-bit value specified in the array argumentseed16v. The previous value ofXiis copied into an internal buffer and a pointer to this buffer is returned byseed48(). The initialization functionlcong48() allows the user to specify initial values forXi,aandc. Array argument elementsparam[0-2]specifyXi,param[3-5]specifya, andparam[6]specifiesc. Afterlcong48() has been called, a subsequent call to eithersrand48() orseed48() will restore the standard values ofaandc.

**ATTRIBUTES**

For an explanation of the terms used in this section, seeattributes(7). ┌──────────────────────┬───────────────┬────────────────────────┐ │Interface│Attribute│Value│ ├──────────────────────┼───────────────┼────────────────────────┤ │drand48(),erand48(), │ Thread safety │ MT-Unsafe race:drand48 │ │lrand48(),nrand48(), │ │ │ │mrand48(),jrand48(), │ │ │ │srand48(),seed48(), │ │ │ │lcong48() │ │ │ └──────────────────────┴───────────────┴────────────────────────┘ The above functions record global state information for the random number generator, so they are not thread-safe.

**CONFORMING** **TO**

POSIX.1-2001, POSIX.1-2008, SVr4.

**SEE** **ALSO**

rand(3),random(3)

**COLOPHON**

This page is part of release 4.15 of the Linuxman-pagesproject. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. 2017-09-15 DRAND48(3)