GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


Manpage of DRAND48

DRAND48

Index
 

NAME

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

SYNOPSIS

#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]);
 

DESCRIPTION

These functions generate pseudo-random numbers using the linear congruential algorithm and 48-bit integer arithmetic.

The fBdrand48()fP and fBerand48()fP functions return non-negative double-precision floating-point values uniformly distributed between [0.0, 1.0).

The fBlrand48()fP and fBnrand48()fP functions return non-negative long integers uniformly distributed between 0 and 2^31.

The fBmrand48()fP and fBjrand48()fP functions return signed long integers uniformly distributed between -2^31 and 2^31.

The fBsrand48()fP, fBseed48()fP and fBlcong48()fP functions are initialization functions, one of which should be called before using fBdrand48()fP, fBlrand48()fP or fBmrand48()fP. The functions fBerand48()fP, fBnrand48()fP and fBjrand48()fP do not require an initialization function to be called first.

All the functions work by generating a sequence of 48-bit integers, fIXifP, according to the linear congruential formula:

Xn+1 = (aXn + c) mod m, where n >= 0

The parameter fImfP = 2^48, hence 48-bit integer arithmetic is performed. Unless fBlcong48()fP is called, fIafP and fIcfP are given by:

a = 0x5DEECE66D c = 0xB

The value returned by any of the functions fBdrand48()fP, fBerand48()fP, fBlrand48()fP, fBnrand48()fP, fBmrand48()fP or fBjrand48()fP is computed by first generating the next 48-bit fIXifP in 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 of fIXifP and transformed into the returned value.

The functions fBdrand48()fP, fBlrand48()fP and fBmrand48()fP store the last 48-bit fIXifP generated in an internal buffer. The functions fBerand48()fP, fBnrand48()fP and fBjrand48()fP require the calling program to provide storage for the successive fIXifP values in the array argument fIxsubifP. The functions are initialized by placing the initial value of fIXifP into the array before calling the function for the first time.

The initializer function fBsrand48()fP sets the high order 32-bits of fIXifP to the argument fIseedvalfP. The low order 16-bits are set to the arbitrary value 0x330E.

The initializer function fBseed48()fP sets the value of fIXifP to the 48-bit value specified in the array argument fIseed16vfP. The previous value of fIXifP is copied into an internal buffer and a pointer to this buffer is returned by fBseed48()fP.

The initialization function fBlcong48()fP allows the user to specify initial values for fIXifP, fIafP and fIcfP. Array argument elements fIparam[0-2]fP specify fIXifP, fIparam[3-5]fP specify fIafP, and fIparam[6]fP specifies fIcfP. After fBlcong48()fP has been called, a subsequent call to either fBsrand48()fP or fBseed48()fP will restore the standard values of fIafP and fIcfP.  

CONFORMING TO

SVID 3  

NOTES

These functions are declared obsolete by SVID 3, which states that rand(3) should be used instead.  

SEE ALSO

rand(3), random(3)


 

Index

NAME
SYNOPSIS
DESCRIPTION
CONFORMING TO
NOTES
SEE ALSO