Files
seta75D ff309bfe1c Init
2021-10-11 18:37:13 -03:00

236 lines
6.8 KiB
Groff

'\" e
.\" @(#)drand48.3 1.1 94/10/31 SMI; from S5
.TH DRAND48 3 "7 February 1989"
.EQ
delim $$
.EN
.SH NAME
drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48 \- generate uniformly distributed pseudo-random numbers
.SH SYNOPSIS
.nf
.B double drand48(\|)
.LP
.B double erand48(xsubi)
.B unsigned short xsubi[3];
.LP
.B long lrand48(\|)
.LP
.B long nrand48(xsubi)
.B unsigned short xsubi[3];
.LP
.B long mrand48(\|)
.LP
.B long jrand48(xsubi)
.B unsigned short xsubi[3];
.LP
.B void srand48(seedval)
.B long seedval;
.LP
.B unsigned short \(**seed48(seed16v)
.B unsigned short seed16v[3];
.LP
.B void lcong48(param)
.B unsigned short param[7];
.SH DESCRIPTION
.IX "drand48()" "" "\fLdrand48()\fR \(em generate uniformly distributed random numbers"
.IX "erand48()" "" "\fLerand48()\fR \(em generate uniformly distributed random numbers"
.IX "lrand48()" "" "\fLlrand48()\fR \(em generate uniformly distributed random numbers"
.IX "nrand48()" "" "\fLnrand48()\fR \(em generate uniformly distributed random numbers"
.IX "mrand48()" "" "\fLmrand48()\fR \(em generate uniformly distributed random numbers"
.IX "jrand48()" "" "\fLjrand48()\fR \(em generate uniformly distributed random numbers"
.IX "srand48()" "" "\fLsrand48()\fR \(em generate uniformly distributed random numbers"
.IX "seed48()" "" "\fLseed48()\fR \(em generate uniformly distributed random numbers"
.IX "lcong48()" "" "\fLlcong48()\fR \(em generate uniformly distributed random numbers"
.IX "random number generator" \fLdrand48()\fR
.IX "random number generator" \fLerand48()\fR
.IX "random number generator" \fLjrand48()\fR
.IX "random number generator" \fLlrand48()\fR
.IX "random number generator" \fLmrand48()\fR
.IX "random number generator" \fLnrand48()\fR
.IX "random number generator" \fLsrand48()\fR
.IX "random number generator" \fLseed48()\fR
.IX "random number generator" \fLlcong48()\fR
.IX "generate random numbers" "drand48()" "" "\fLdrand48()\fR"
.IX "generate random numbers" "erand48()" "" "\fLerand48()\fR"
.IX "generate random numbers" "jrand48()" "" "\fLjrand48()\fR"
.IX "generate random numbers" "lrand48()" "" "\fLlrand48()\fR"
.IX "generate random numbers" "mrand48()" "" "\fLmrand48()\fR"
.IX "generate random numbers" "nrand48()" "" "\fLnrand48()\fR"
.IX "generate random numbers" "srand48()" "" "\fLsrand48()\fR"
.IX "generate random numbers" "seed48()" "" "\fLseed48()\fR"
.IX "generate random numbers" "lcong48()" "" "\fLlcong48()\fR"
.LP
This family of functions generates pseudo-random numbers using the
well-known linear congruential algorithm and 48-bit integer arithmetic.
.LP
.B drand48(\|)
and
.B erand48(\|)
return non-negative double-precision floating-point values
uniformly distributed over the interval $[0.0,~1.0).$
.LP
.B lrand48(\|)
and
.B nrand48(\|)
return non-negative long integers uniformly distributed over the
interval
.if n .ig
$[0,~2 sup 31 ).$
..
.if t .ig
(0, ~2**31).
..
.LP
.B mrand48(\|)
and
.B jrand48(\|)
return signed long integers uniformly distributed over the interval
.if n .ig
$[-2 sup 31 ,~2 sup 31 ).$
..
.if t .ig
[-2**31 ~2**31).
..
.LP
.BR srand48(\|) ,
.BR seed48(\|) ,
and
.B lcong48(\|)
are initialization entry points, one of which should be invoked before
either
.BR drand48(\|) ,
.BR lrand48(\|) ,
or
.B mrand48(\|)
is called.
Although it is not recommended practice,
constant default initializer values will be supplied automatically if
.BR drand48(\|) ,
.BR lrand48(\|) ,
or
.B mrand48(\|)
is called without a prior call to an initialization entry point.
.BR erand48(\|) ,
.BR nrand48(\|) ,
and
.B jrand48(\|)
do not require an initialization entry point to be called first.
.LP
All the routines work by generating a sequence of 48-bit integer values,
$X sub i ,$ according to the linear congruential formula
.IP
.EQ I
X sub{n+1}~=~(aX sub n^+^c) sub{roman mod~m}~~~~~~~~n>=0.
.EN
.LP
The parameter
.if n .ig
$m^=^2 sup 48$;
..
.if t .ig
m=2**48;
..
hence 48-bit integer arithmetic is performed.
Unless
.B lcong48(\|)
has been invoked, the multiplier value $a$ and the addend value $c$
are given by
.LP
.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
.LP
The value returned by any of the functions
.BR drand48(\|) ,
.BR erand48(\|) ,
.BR lrand48(\|) ,
.BR nrand48(\|) ,
.BR mrand48(\|) ,
or
.B 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.
.LP
.BR drand48(\|) ,
.BR lrand48(\|) ,
and
.B mrand48(\|)
store the last 48-bit $X sub i$ generated in an internal buffer;
that is why they must be initialized prior to being invoked.
The functions
.BR erand48(\|) ,
.BR nrand48(\|) ,
and
.B 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.
That is why these routines do not have to be initialized; the calling
program merely has to place the desired initial value of $X sub i$ into the
array and pass it as an argument.
By using different
arguments, functions
.BR erand48(\|) ,
.BR nrand48(\|) ,
and
.B jrand48(\|)
allow separate modules of a large program to generate several
.I independent
streams of pseudo-random numbers, that is,
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.
.LP
The initializer function
.B 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 .$
.LP
The initializer function
.B 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
.BR seed48(\|) ,
and a pointer to this buffer is the value returned by
.BR 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
.B seed48(\|)
when the program is restarted.
.LP
The initialization function
.B lcong48(\|)
allows the user to specify the initial $X sub i ,$ the multiplier value
$a,$ and the addend value $c.$
Argument array elements
.IR param [0-2]
specify $X sub i ,$
.IR param [3-5]
specify the multiplier $a,$ and
.IR param [6]
specifies the 16-bit addend $c.$ After
.B lcong48(\|)
has been called, a subsequent call to either
.B srand48(\|)
or
.B seed48(\|)
will restore the \*(lqstandard\*(rq multiplier and addend values, $a$ and $c,$
specified on the previous page.
.SH SEE ALSO
.BR rand (3V)