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

802 lines
14 KiB
Plaintext

'\" e
.\" @(#)drand48.eqn 1.1 94/10/31 SMI; from S5
.TH DRAND48 3 "31 January 1990"
.EQ
.nr 99 \n(.s
.nr 98 \n(.f
.ps 10
.ft 2
.ps \n(99
.ft \n(98
.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
.nr 99 \n(.s
.nr 98 \n(.f
.rm 11
.as 11 "uniformly distributed over the interval
.ps 10
.ft 2
.ds 12 "\f1[\fP\f10\fP\f1.\fP\f10\fP\f1,\fP
.ds 13 "\
.as 12 "\*(13
.ds 13 "\f11\fP\f1.\fP\f10\fP\f1)\fP\f1.\fP
.as 12 "\*(13
.ds 12 \x'0'\f2\s10\*(12\s\n(99\f\n(98
.as 11 \*(12
.ps \n(99
.ft \n(98
.as 11 "
.ps \n(99
.ft \n(98
\*(11
.LP
.B lrand48(\|)
and
.B nrand48(\|)
return non-negative long integers uniformly distributed over the
interval
.if n .ig
.nr 99 \n(.s
.nr 98 \n(.f
.rm 11
.ps 10
.ft 2
.ds 12 "\f1[\fP\f10\fP\f1,\fP
.ds 13 "\
.as 12 "\*(13
.ds 13 "\f12\fP
.ds 14 "\f13\fP\f11\fP
.as 13 \v'-33u'\s-3\*(14\s+3\v'33u'
.as 12 "\*(13
.ds 13 "\f1)\fP\f1.\fP
.as 12 "\*(13
.ds 12 \x'0'\f2\s10\*(12\s\n(99\f\n(98
.as 11 \*(12
.ps \n(99
.ft \n(98
.as 11 "
.ps \n(99
.ft \n(98
\*(11
..
.if t .ig
(0, ~2**31).
..
.LP
.B mrand48(\|)
and
.B jrand48(\|)
return signed long integers uniformly distributed over the interval
.if n .ig
.nr 99 \n(.s
.nr 98 \n(.f
.rm 11
.ps 10
.ft 2
.ds 12 "\f1[\fP\(mi\f12\fP
.ds 13 "\f13\fP\f11\fP
.as 12 \v'-33u'\s-3\*(13\s+3\v'33u'
.ds 13 "\f1,\fP
.as 12 "\*(13
.ds 13 "\
.as 12 "\*(13
.ds 13 "\f12\fP
.ds 14 "\f13\fP\f11\fP
.as 13 \v'-33u'\s-3\*(14\s+3\v'33u'
.as 12 "\*(13
.ds 13 "\f1)\fP\f1.\fP
.as 12 "\*(13
.ds 12 \x'0'\f2\s10\*(12\s\n(99\f\n(98
.as 11 \*(12
.ps \n(99
.ft \n(98
.as 11 "
.ps \n(99
.ft \n(98
\*(11
..
.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,
.nr 99 \n(.s
.nr 98 \n(.f
.rm 11
.ps 10
.ft 2
.ds 12 "X
.ds 13 "i
.as 12 \v'18u'\s-3\*(13\s+3\|\v'-18u'
.ds 13 "\f1,\fP
.as 12 "\*(13
.ds 12 \x'0'\f2\s10\*(12\s\n(99\f\n(98\x'3u'
.as 11 \*(12
.ps \n(99
.ft \n(98
.as 11 " according to the linear congruential formula
.ps \n(99
.ft \n(98
\*(11
.IP
.EQ I
.nr 99 \n(.s
.nr 98 \n(.f
.ps 10
.ft 2
.ds 11 "X
.ds 12 "n\|\(pl\f11\fP
.as 11 \v'18u'\s-3\*(12\s+3\v'-18u'
.ds 12 "\
.as 11 "\*(12
.ds 12 "\(eq
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\f1(\fPaX
.ds 13 "n
.as 12 \v'18u'\s-3\*(13\s+3\|\v'-18u'
.as 11 "\*(12
.ds 12 "\|
.as 11 "\*(12
.ds 12 "\(pl
.as 11 "\*(12
.ds 12 "\|
.as 11 "\*(12
.ds 12 "c\|\f1)\fP
.ft 1
.ds 13 "mod
.ds 13 \f1\*(13\f2
.ft 2
.ds 14 "\
.as 13 "\*(14
.ds 14 "m
.as 13 "\*(14
.as 12 \v'18u'\s-3\*(13\s+3\|\v'-18u'
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "n\|\(>=\f10\fP\f1.\fP
.as 11 "\*(12
.ds 11 \x'0'\f2\s10\*(11\s\n(99\f\n(98\x'3u'
.nr 11 \w'\*(11'
.nr MK 0
.if 99>\n(.v .ne 99u
.rn 11 10
\*(10
.ps \n(99
.ft \n(98
.EN
.LP
The parameter
.if n .ig
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.ps 10
.ft 2
.ds 13 "m
.ds 14 "\|
.as 13 "\|\*(14
.ds 14 "\(eq
.as 13 "\*(14
.ds 14 "\|
.as 13 "\*(14
.ds 14 "\f12\fP
.ds 15 "\f14\fP\f18\fP
.as 14 \v'-33u'\s-3\*(15\s+3\v'33u'
.as 13 "\*(14
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 ";
.ps \n(99
.ft \n(98
\*(12
..
.if t .ig
m=2**48;
..
hence 48-bit integer arithmetic is performed.
Unless
.B lcong48(\|)
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "has been invoked, the multiplier value
.ps 10
.ft 2
.ds 13 "a
.ds 13 \x'0'\f2\s10\*(13\|\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " and the addend value
.ps 10
.ft 2
.ds 13 "c
.ds 13 \x'0'\f2\s10\*(13\|\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 "
.ps \n(99
.ft \n(98
\*(12
are given by
.LP
.RS 6
.EQ I
.nr 99 \n(.s
.nr 98 \n(.f
.ps 10
.ft 2
.ds 11 "a
.ds 12 "\
.as 11 "\|\*(12
.ds 12 "\(eq
.ds 12 \k(97\*(12
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ft 1
.ds 12 "\f15\fPDEECE\f16\fP\f16\fPD
.ds 12 \f1\*(12\f2
.ft 2
.as 11 "\*(12
.ds 12 "\|
.ds 13 "\f11\fP\f16\fP
.as 12 \v'18u'\s-3\*(13\s+3\v'-18u'
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\(eq
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ft 1
.ds 12 "\f12\fP\f17\fP\f13\fP\f16\fP\f17\fP\f13\fP\f11\fP\f16\fP\f13\fP\f11\fP\f15\fP\f15\fP
.ds 12 \f1\*(12\f2
.ft 2
.as 11 "\*(12
.ds 12 "\|
.ds 13 "\f18\fP
.as 12 \v'18u'\s-3\*(13\s+3\v'-18u'
.as 11 "\*(12
.ds 11 \x'0'\f2\s10\*(11\s\n(99\f\n(98\x'3u'
.nr 11 \w'\*(11'
.nr MK 1
.if 99>\n(.v .ne 99u
.rn 11 10
\*(10
.ps \n(99
.ft \n(98
.EN
.br
.EQ I
.nr 99 \n(.s
.nr 98 \n(.f
.ps 10
.ft 2
.ds 11 "c
.ds 12 "\
.as 11 "\|\*(12
.ds 12 "\(eq
.nr 11 \w'\s10\*(11'
.ds 11 \h'|\n(97u-\n(11u'\*(11
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ft 1
.ds 12 "B
.ds 12 \f1\*(12\f2
.ft 2
.as 11 "\*(12
.ds 12 "\|
.ds 13 "\f11\fP\f16\fP
.as 12 \v'18u'\s-3\*(13\s+3\v'-18u'
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ds 12 "\(eq
.as 11 "\*(12
.ds 12 "\
.as 11 "\*(12
.ft 1
.ds 12 "\f11\fP\f13\fP
.ds 12 \f1\*(12\f2
.ft 2
.as 11 "\*(12
.ds 12 "\|
.ds 13 "\f18\fP
.as 12 \v'18u'\s-3\*(13\s+3\v'-18u'
.as 11 "\*(12
.ds 12 ".
.as 11 "\*(12
.ds 11 \x'0'\f2\s10\*(11\s\n(99\f\n(98\x'3u'
.nr 11 \w'\*(11'
.nr MK 2
.if 99>\n(.v .ne 99u
.rn 11 10
\*(10
.ps \n(99
.ft \n(98
.EN
.RE
.LP
The value returned by any of the functions
.BR drand48(\|) ,
.BR erand48(\|) ,
.BR lrand48(\|) ,
.BR nrand48(\|) ,
.BR mrand48(\|) ,
or
.B jrand48(\|)
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "is computed by first generating the next 48-bit
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " in the sequence.
.ps \n(99
.ft \n(98
\*(12
Then the appropriate number of bits, according to the type of data item
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "to be returned, are copied from the high-order (leftmost) bits of
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 "
.ps \n(99
.ft \n(98
\*(12
and transformed into the returned value.
.LP
.BR drand48(\|) ,
.BR lrand48(\|) ,
and
.B mrand48(\|)
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "store the last 48-bit
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " generated in an internal buffer;
.ps \n(99
.ft \n(98
\*(12
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
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "successive
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " values in the array
.ps \n(99
.ft \n(98
\*(12
specified as an argument when the functions are invoked.
That is why these routines do not have to be initialized; the calling
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "program merely has to place the desired initial value of
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " into the
.ps \n(99
.ft \n(98
\*(12
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(\|)
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "sets the high-order 32 bits of
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " to the 32 bits contained in
.ps \n(99
.ft \n(98
\*(12
its argument.
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "The low-order 16 bits of
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " are set to the arbitrary value
.ps \n(99
.ft \n(98
\*(12
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.ps 10
.ft 2
.ft 1
.ds 13 "\f13\fP\f13\fP\f10\fPE
.ds 13 \f1\*(13\f2
.ft 2
.ds 14 "\f11\fP\f16\fP
.as 13 \v'18u'\s-3\*(14\s+3\v'-18u'
.ds 14 ".
.as 13 "\*(14
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 "
.ps \n(99
.ft \n(98
\*(12
.LP
The initializer function
.B seed48(\|)
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "sets the value of
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " to the 48-bit value specified in the
.ps \n(99
.ft \n(98
\*(12
argument array.
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "In addition, the previous value of
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " is copied into a 48-bit
.ps \n(99
.ft \n(98
\*(12
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
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "\(em use the pointer to get at and store the last
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " value, and
.ps \n(99
.ft \n(98
\*(12
then use this value to reinitialize via
.B seed48(\|)
when the program is restarted.
.LP
The initialization function
.B lcong48(\|)
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "allows the user to specify the initial
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 14 "\f1,\fP
.as 13 "\*(14
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " the multiplier value
.ps \n(99
.ft \n(98
\*(12
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.ps 10
.ft 2
.ds 13 "a\|\f1,\fP
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " and the addend value
.ps 10
.ft 2
.ds 13 "c.
.ds 13 \x'0'\f2\s10\*(13\|\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 "
.ps \n(99
.ft \n(98
\*(12
Argument array elements
.IR param [0-2]
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "specify
.ps 10
.ft 2
.ds 13 "X
.ds 14 "i
.as 13 \v'18u'\s-3\*(14\s+3\|\v'-18u'
.ds 14 "\f1,\fP
.as 13 "\*(14
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98\x'3u'
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 "
.ps \n(99
.ft \n(98
\*(12
.IR param [3-5]
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "specify the multiplier
.ps 10
.ft 2
.ds 13 "a\|\f1,\fP
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " and
.ps \n(99
.ft \n(98
\*(12
.IR param [6]
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "specifies the 16-bit addend
.ps 10
.ft 2
.ds 13 "c.
.ds 13 \x'0'\f2\s10\*(13\|\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " After
.ps \n(99
.ft \n(98
\*(12
.B lcong48(\|)
has been called, a subsequent call to either
.B srand48(\|)
or
.B seed48(\|)
.nr 99 \n(.s
.nr 98 \n(.f
.rm 12
.as 12 "will restore the \*(lqstandard\*(rq multiplier and addend values,
.ps 10
.ft 2
.ds 13 "a
.ds 13 \x'0'\f2\s10\*(13\|\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 " and
.ps 10
.ft 2
.ds 13 "c\|\f1,\fP
.ds 13 \x'0'\f2\s10\*(13\s\n(99\f\n(98
.as 12 \*(13
.ps \n(99
.ft \n(98
.as 12 "
.ps \n(99
.ft \n(98
\*(12
specified on the previous page.
.SH SEE ALSO
.BR rand (3V)