Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
drand48(3)
Edit
PageHistory
Diff
Info
LikePages
!!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 __drand48()__ and __erand48()__ functions return non-negative double-precision floating-point values uniformly distributed between [[0.0, 1.0). The __lrand48()__ and __nrand48()__ functions return non-negative long integers uniformly distributed between 0 and 2^31. The __mrand48()__ and __jrand48()__ functions return signed long integers uniformly distributed between -2^31 and 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 48-bit integers, ''Xi'', according to the linear congruential formula: __Xn+1 = (aXn + c) mod m, where n >= 0__ The parameter ''m'' = 2^48, hence 48-bit integer arithmetic is performed. Unless __lcong48()__ is called, ''a'' and ''c'' are given by: __a = 0x5DEECE66D__ __c = 0xB__ The value returned by any of the functions __drand48()__, __erand48()__, __lrand48()__, __nrand48()__, __mrand48()__ or __jrand48()__ is computed by first generating the next 48-bit ''Xi'' 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 ''Xi'' and transformed into the returned value. The functions __drand48()__, __lrand48()__ and __mrand48()__ store the last 48-bit ''Xi'' generated in an internal buffer. The functions __erand48()__, __nrand48()__ and __jrand48()__ require the calling program to provide storage for the successive ''Xi'' values in the array argument ''xsubi''. The functions are initialized by placing the initial value of ''Xi'' into the array before calling the function for the first time. The initializer function __srand48()__ sets the high order 32-bits of ''Xi'' to the argument ''seedval''. The low order 16-bits are set to the arbitrary value 0x330E. The initializer function __seed48()__ sets the value of ''Xi'' to the 48-bit value specified in the array argument ''seed16v''. The previous value of ''Xi'' is 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'', ''a'' and ''c''. Array argument elements ''param[[0-2]'' specify ''Xi'', ''param[[3-5]'' 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 ''a'' and ''c''. !!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)
10 pages link to
drand48(3)
:
nrand48(3)
lrand48(3)
srand48(3)
seed48(3)
lcong48(3)
Man3d
erand48(3)
mrand48(3)
jrand48(3)
RandomNumberGenerator
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.