# FreeBSD Manual Pages

drand48(3C) Standard C Library Functions drand48(3C)NAMEdrand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48 - generate uniformly distributed pseudo-random numbersSYNOPSIS#include <stdlib.h>doubledrand48(void);doubleerand48(unsignedshortxi[3]);longlrand48(void);longnrand48(unsignedshortxi[3]);longmrand48(void);longjrand48(unsignedshortxi[3]);voidsrand48(longseedval);unsignedshort*seed48(unsignedshortseed16v[3]);voidlcong48(unsignedshortparam[7]);DESCRIPTIONThis family of functions generates pseudo-random numbers using the well-known linear congruential algorithm and 48-bit integer arithmetic. Functionsdrand48()anderand48()return non-negative double-precision floating-point values uniformly distributed over the interval [0.0, 1.0). Functionslrand48()andnrand48()return non-negative long integers uniformly distributed over the interval [0, 2**31]. Functionsmrand48()andjrand48()return signed long integers uniformly distributed over the interval [-2**31 , 2**31 ]. Functionssrand48(),seed48(), andlcong48()are initialization entry points, one of which should be invoked before eitherdrand48(),lrand48(), ormrand48()is called. (Although it is not recommended practice, constant default initializer values will be supplied automat- ically ifdrand48(),lrand48(), ormrand48()is called without a prior call to an initialization entry point.) Functionserand48(),nrand48(),andjrand48()do not require an initialization entry point to be called first. All the routines work by generating a sequence of 48-bit integer val- ues, Xi , according to the linear congruential formula X n+1= (aX n+c) mod m n>=0. The parameterm= 2**48; hence 48-bit integer arithmetic is performed. Unlesslcong48()has been invoked, the multiplier valueaand the addend valuecare given bya= 5DEECE66D16 = 2736731631558c= B16 = 138 . The value returned by any of the functionsdrand48(),erand48(),lrand48(),nrand48(),mrand48(), orjrand48()is computed by first gen- erating the next 48-bit Xi 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 Xi and transformed into the re- turned value. The functionsdrand48(),lrand48(), andmrand48()store the last 48-bit Xi generated in an internal buffer. Xi must be initialized prior to be- ing invoked. The functionserand48(),nrand48(), andjrand48()require the calling program to provide storage for the successive Xi values in the array specified as an argument when the functions are invoked. These routines do not have to be initialized; the calling program must place the desired initial value of Xi into the array and pass it as an argument. By using different arguments, functionserand48(),nrand48(), andjrand48()allow separate modules of a large program to generate severalindependentstreams of pseudo-random numbers, that is, the se- quence of numbers in each stream willnotdepend upon how many times the routines have been called to generate numbers for the other streams. The initializer functionsrand48()sets the high-order 32 bits of Xi to the 32 bits contained in its argument. The low-order 16 bits of Xi are set to the arbitrary value 330E16 . The initializer functionseed48()sets the value of Xi to the 48-bit value specified in the argument array. In addition, the previous value of Xi is copied into a 48-bit internal buffer, used only byseed48(), and a pointer to this buffer is the value returned byseed48(). 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 Xi value, and then use this value to reinitialize usingseed48()when the program is restarted. The initialization functionlcong48()allows the user to specify the initial Xi the multiplier valuea, and the addend valuec. Argument ar- ray elementsparam[0-2]specify Xi,param[3-5]specify the multipliera, andparam[6]specifies the 16-bit addendc. Afterlcong48()has been called, a subsequent call to eithersrand48()orseed48()will restore the ``standard'' multiplier and addend values,aandc, specified above.ATTRIBUTESSeeattributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ |ATTRIBUTETYPE|ATTRIBUTEVALUE| +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+SEE ALSOrand(3C),attributes(5),standards(5) SunOS 5.10 24 Jul 2002 drand48(3C)

NAME | SYNOPSIS | DESCRIPTION | ATTRIBUTES | SEE ALSO

Want to link to this manual page? Use this URL:

<https://www.freebsd.org/cgi/man.cgi?query=drand48&sektion=3c&manpath=SunOS+5.10>