|
|
researchv10 Dan Cross
.TH DRAND48 3L "630 MTG"
.SH NAME
drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48 \- generate uniformly distributed pseudo-random numbers
.SH SYNOPSIS
.EQ
delim $$
.EN
.B double drand48 ( )
.sp
\f3double erand48 ( xsubi )\f1
.br
\f3unsigned short xsubi [3];\f1
.sp
.B long lrand48 ( )
.sp
\f3long nrand48 ( xsubi )\f1
.br
\f3unsigned short xsubi [3];\f1
.sp
.B long mrand48 ( )
.sp
\f3long jrand48 ( xsubi )\f1
.br
\f3unsigned short xsubi [3];\f1
.sp
.B void srand48 (seedval)
.br
.B long seedval;
.sp
.B unsigned short \(**seed48 (seed16v)
.br
.B unsigned short seed16v[3];
.sp
.B void lcong48 (param)
.br
.B unsigned short param[7];
.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
.I drand48\^
and
.I erand48\^
return non-negative double-precision floating-point values
uniformly distributed over the interval $[0.0,~1.0).$
.PP
Functions
.I lrand48\^
and
.I nrand48\^
return non-negative long integers uniformly distributed over the
interval $[0,~2 sup 31 ).$
.PP
Functions
.I mrand48\^
and
.I jrand48\^
return signed long integers uniformly distributed over the interval
$[-2 sup 31 ,~2 sup 31 ).$
.PP
Functions
.I srand48, seed48\^
and
.I lcong48\^
are initialization entry points, one of which should be invoked before
either
.I drand48, lrand48\^
or
.I mrand48\^
is called.
(Although it is not recommended practice,
constant default initializer values will be supplied automatically if
.I drand48, lrand48\^
or
.I mrand48\^
is called without a prior call to an initialization entry point.)
Functions
.I erand48, nrand48\^
and
.I jrand48\^
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
.I lcong48\^
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
.I drand48, erand48, lrand48, nrand48, mrand48\^
or
.I jrand48\^
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 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
.I drand48, lrand48\^
and
.I mrand48\^
store the last 48-bit $X sub i$ generated in an internal buffer,
and must be initialized prior to being invoked.
The functions
.I erand48, nrand48\^
and
.I jrand48\^
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
.I erand48, nrand48\^
and
.I jrand48\^
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
.I srand48\^
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
.I seed48\^
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
.I seed48,\^
and a pointer to this buffer is the value returned by
.I 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
\(em use the pointer to get at and store the last $X sub i$ value, and
then use this value to reinitialize via
.I seed48\^
when the program is restarted.
.PP
The initialization function
.I lcong48\^
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
.I lcong48\^
has been called, a subsequent call to either
.I srand48\^
or
.I seed48\^
will restore the ``standard'' multiplier and addend values, $a$ and $c,$
specified on the previous page.
.SH "SEE ALSO"
rand(3L).
.Ee
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.