# drand48

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



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


## SYNOPSIS



           #include <stdlib.h>
    
           double drand48(void);
           double erand48(unsigned short _xsubi_[3]);
           long jrand48(unsigned short _xsubi_[3]);
           void lcong48(unsigned short _param_[7]);
           long lrand48(void);
           long mrand48(void);
           long nrand48(unsigned short _xsubi_[3]);
           unsigned short *seed48(unsigned short _seed16v_[3]);
           void srand48(long _seedval_);
    


## DESCRIPTION



           This family of functions shall generate pseudo-random numbers
           using a linear congruential algorithm and 48-bit integer
           arithmetic.
    
           The _drand48_() and _erand48_() functions shall return non-negative,
           double-precision, floating-point values, uniformly distributed
           over the interval [0.0,1.0).
    
           The _lrand48_() and _nrand48_() functions shall return non-negative,
           long integers, uniformly distributed over the interval [0,231).
    
           The _mrand48_() and _jrand48_() functions shall return signed long
           integers uniformly distributed over the interval [-231,231).
    
           The _srand48_(), _seed48_(), and _lcong48_() functions are
           initialization entry points, one of which should be invoked before
           either _drand48_(), _lrand48_(), or _mrand48_() is called. (Although it
           is not recommended practice, constant default initializer values
           shall be supplied automatically if _drand48_(), _lrand48_(), or
           _mrand48_() is called without a prior call to an initialization
           entry point.) The _erand48_(), _nrand48_(), and _jrand48_() functions do
           not require an initialization entry point to be called first.
    
           All the routines work by generating a sequence of 48-bit integer
           values, _X_ __i_ , according to the linear congruential formula:
    
                  _Xn_ +1 = (_aX_ __n_ +_c_)mod _m_        _n_ ≥ 0
    
           The parameter _m_ =2 _^_ 48; hence 48-bit integer arithmetic is
           performed. Unless _lcong48_() is invoked, the multiplier value _a_ and
           the addend value _c_ are given by:
    
                  _a_ = 5DEECE66D16 = 2736731631558
    
                  _c_ = B16 = 138
    
           The value returned by any of the _drand48_(), _erand48_(), _jrand48_(),
           _lrand48_(), _mrand48_(), or _nrand48_() functions is computed by first
           generating the next 48-bit _X_ __i_ in the sequence. Then the
           appropriate number of bits, according to the type of data item to
           be returned, are copied from the high-order (leftmost) bits of _X_ __i_
           and transformed into the returned value.
    
           The _drand48_(), _lrand48_(), and _mrand48_() functions store the last
           48-bit _X_ __i_ generated in an internal buffer; that is why the
           application shall ensure that these are initialized prior to being
           invoked. The _erand48_(), _nrand48_(), and _jrand48_() functions require
           the calling program to provide storage for the successive _X_ __i_
           values in the array specified as an argument when the functions
           are invoked. That is why these routines do not have to be
           initialized; the calling program merely has to place the desired
           initial value of _X_ __i_ into the array and pass it as an argument.
           By using different arguments, _erand48_(), _nrand48_(), and _jrand48_()
           allow separate modules of a large program to generate several
           _independent_ streams of pseudo-random numbers; that is, the
           sequence of numbers in each stream shall _not_ depend upon how many
           times the routines are called to generate numbers for the other
           streams.
    
           The initializer function _srand48_() sets the high-order 32 bits of
           _X_ __i_ to the low-order 32 bits contained in its argument. The low-
           order 16 bits of _X_ __i_ are set to the arbitrary value 330E_16 .
    
           The initializer function _seed48_() sets the value of _X_ __i_ to the
           48-bit value specified in the argument array. The low-order 16
           bits of _X_ __i_ are set to the low-order 16 bits of _seed16v_[_0_].  The
           mid-order 16 bits of _X_ __i_ are set to the low-order 16 bits of
           _seed16v_[_1_].  The high-order 16 bits of _X_ __i_ are set to the low-
           order 16 bits of _seed16v_[_2_].  In addition, the previous value of
           _X_ __i_ is copied into a 48-bit internal buffer, used only by
           _seed48_(), and a pointer to this buffer is the value returned by
           _seed48_().  This returned pointer, which can just be ignored if not
           needed, is useful if a program is to be restarted from a given
           point at some future time—use the pointer to get at and store the
           last _X_ __i_ value, and then use this value to reinitialize via
           _seed48_() when the program is restarted.
    
           The initializer function _lcong48_() allows the user to specify the
           initial _X_ __i_ , the multiplier value _a_ , and the addend value _c_.
           Argument array elements _param_[_0-2_] specify _X_ __i_ , _param_[_3-5_]
           specify the multiplier _a_ , and _param_[_6_] specifies the 16-bit addend
           _c_. After _lcong48_() is called, a subsequent call to either
           _srand48_() or _seed48_() shall restore the standard multiplier and
           addend values, _a_ and _c,_ specified above.
    
           The _drand48_(), _lrand48_(), and _mrand48_() functions need not be
           thread-safe.
    


## RETURN VALUE



           As described in the DESCRIPTION above.
    


## ERRORS



           No errors are defined.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           These functions should be avoided whenever non-trivial
           requirements (including safety) have to be fulfilled.
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           None.
    


* * *