'\"! eqn | mmdoc
'\"macro stdmacro
.if n .pH g3c.drand48 @(#)drand48	40.12 of 10/27/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} drand48 3C "C Programming Language Utilities" "\&"
.if \nX=1 .ds x} drand48 3C "C Programming Language Utilities"
.if \nX=2 .ds x} drand48 3C "" "\&"
.if \nX=3 .ds x} drand48 "" "" "\&"
.TH \*(x}
.if n .ll 79
.EQ
.EN
.SH NAME
\f4drand48\f1, \f4erand48\f1, \f4lrand48\f1, \f4nrand48\f1, \f4mrand48\f1, \f4jrand48\f1, \f4srand48\f1, \f4seed48\f1, \f4lcong48\f1 \- generate uniformly distributed pseudo-random numbers
.SH SYNOPSIS
.nf
\f4#include <stdlib.h>\f1
.PP
\f4double drand48 (void);\f1
.PP
\f4double erand48 (unsigned short xsubi[3]\|);\f1
.PP
\f4long lrand48 (void);\f1
.PP
\f4long nrand48 (unsigned short xsubi[3]\|);\f1
.PP
\f4long mrand48 (void);\f1
.PP
\f4long jrand48 (unsigned short xsubi[3]\|);\f1
.PP
\f4void srand48 (long seedval);\f1
.PP
\f4unsigned short \(**seed48 (unsigned short seed16v[3]\|);\fP
.PP
\f4void lcong48 (unsigned short param[7]\|);\f1
.SH DESCRIPTION
.EQ
delim $$
.EN
This family of functions generates pseudo-random numbers using the
well-known linear congruential algorithm and 48-bit integer arithmetic.
.PP
Functions
\f4drand48\fP
and
\f4erand48\fP
return non-negative double-precision floating-point values
uniformly distributed over the interval $[0.0,~1.0).$
.PP
Functions
\f4lrand48\fP
and
\f4nrand48\fP
return non-negative long integers uniformly distributed over the
interval $[0,~2 sup 31 ).$
.PP
Functions
\f4mrand48\fP
and
\f4jrand48\fP
return signed long integers uniformly distributed over the interval
$[-2 sup 31 ,~2 sup 31 ).$
.PP
Functions
\f4srand48\fP, \f4seed48\fP,
and
\f4lcong48\fP
are initialization entry points, one of which should be invoked before
either
\f4drand48\fP, \f4lrand48\fP,
or
\f4mrand48\fP
is called.
(Although it is not recommended practice,
constant default initializer values will be supplied automatically if
\f4drand48\fP, \f4lrand48\fP,
or
\f4mrand48\fP
is called without a prior call to an initialization entry point.)
Functions
\f4erand48\fP, \f4nrand48\fP,
and
\f4jrand48\fP
do not require an initialization entry point to be called first.
.PP
All the routines work by generating a sequence of 48-bit integer values,
$X sub i ,$ according to the linear congruential formula
.PP
.ce
.EQ I
X sub{n+1}~=~(aX sub n^+^c) sub{roman mod~m}~~~~~~~~n>=0.
.EN
.PP
The parameter $m^=^2 sup 48$; hence 48-bit integer arithmetic is
performed.
Unless
\f4lcong48\fP
has been invoked, the multiplier value $a$ and the addend value $c$
are given by
.PP
.RS 6
.EQ I
a~mark =~roman 5DEECE66D^sub 16~=~roman 273673163155^sub 8
.EN
.br
.EQ I
c~lineup =~roman B^sub 16~=~roman 13^sub 8 .
.EN
.RE
.PP
The value returned by any of the functions
\f4drand48\fP, \f4erand48\fP, \f4lrand48\fP, \f4nrand48\fP, \f4mrand48\fP,
or
\f4jrand48\fP
is computed by first generating the next 48-bit $X sub i$ in the sequence.
Then the appropriate number of bits, according to the type of\p
.br
.ne2
data item
to be returned, are copied from the high-order (leftmost) bits of $X sub i$
and transformed into the returned value.
.PP
The functions
\f4drand48\fP, \f4lrand48\fP,
and
\f4mrand48\fP
store the last 48-bit $X sub i$ generated in an internal buffer.
$X sub i$ must be initialized prior to being invoked.
The functions
\f4erand48\fP, \f4nrand48\fP,
and
\f4jrand48\fP
require the calling program to provide storage for the
successive $X sub i$ 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 $X sub i$ into the
array and pass it as an argument.
By using different
arguments, functions
\f4erand48\fP, \f4nrand48\fP,
and
\f4jrand48\fP
allow separate modules of a large program to generate several
.I independent\^
streams of pseudo-random numbers, i.e., the sequence of numbers
in each stream will
.I not\^
depend upon how many times the routines have been called to generate
numbers for the other streams.
.PP
The initializer function
\f4srand48\fP
sets the high-order 32 bits of $X sub i$ to the 32 bits contained in
its argument.
The low-order 16 bits of $X sub i$ are set to the arbitrary value
$roman 330E sub 16 .$
.PP
The initializer function
\f4seed48\fP
sets the value of $X sub i$ to the 48-bit value specified in the
argument array.
In addition, the previous value of $X sub i$ is copied into a 48-bit
internal buffer, used only by
\f4seed48\fP,
and a pointer to this buffer is the value returned by
\f4seed48\fP.
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
\(em use the pointer to get at and store the last $X sub i$ value, and
then use this value to reinitialize via
\f4seed48\fP
when the program is restarted.
.PP
The initialization function
\f4lcong48\fP
allows the user to specify the initial $X sub i ,$ the multiplier value
$a,$ and the addend value $c.$
Argument array elements
.I param[0-2]\^
specify $X sub i ,$
.I param[3-5]\^
specify the multiplier $a,$ and
.I param[6]\^
specifies the 16-bit addend $c.$
After
\f4lcong48\fP
has been called, a subsequent call to either
\f4srand48\fP
or
\f4seed48\fP
will restore the ``standard'' multiplier and addend values, $a$ and $c,$
specified on the previous page.
.SH "SEE ALSO"
\f4rand\fP(3C).
.\"	@(#)drand48.3c	6.2 of 10/20/83
.Ee
