394 lines
6.3 KiB
HTML
394 lines
6.3 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of DRAND48</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>DRAND48</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
|
|
lcong48 - generate uniformly distributed pseudo-random numbers
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>></B>
|
|
|
|
<B>double drand48(void);</B>
|
|
|
|
<B>double erand48(unsigned short </B><I>xsubi</I><B>[3]);</B>
|
|
|
|
<B>long int lrand48(void);</B>
|
|
|
|
<B>long int nrand48(unsigned short </B><I>xsubi</I><B>[3]);</B>
|
|
|
|
<B>long int mrand48(void);</B>
|
|
|
|
<B>long int jrand48(unsigned short </B><I>xsubi</I><B>[3]);</B>
|
|
|
|
<B>void srand48(long int </B><I>seedval</I><B>);</B>
|
|
|
|
<B>unsigned short *seed48(unsigned short </B><I>seed16v</I><B>[3]);</B>
|
|
|
|
<B>void lcong48(unsigned short </B><I>param</I><B>[7]);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
|
|
All functions shown above:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_XOPEN_SOURCE
|
|
<BR> || /* Glibc since 2.19: */ _DEFAULT_SOURCE
|
|
<BR> || /* Glibc versions <= 2.19: */ _SVID_SOURCE
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
These functions generate pseudo-random numbers using the linear congruential
|
|
algorithm and 48-bit integer arithmetic.
|
|
<P>
|
|
|
|
The
|
|
<B>drand48</B>()
|
|
|
|
and
|
|
<B>erand48</B>()
|
|
|
|
functions return nonnegative
|
|
double-precision floating-point values uniformly distributed over the interval
|
|
[0.0, 1.0).
|
|
<P>
|
|
|
|
The
|
|
<B>lrand48</B>()
|
|
|
|
and
|
|
<B>nrand48</B>()
|
|
|
|
functions return nonnegative
|
|
long integers uniformly distributed over the interval [0, 2^31).
|
|
<P>
|
|
|
|
The
|
|
<B>mrand48</B>()
|
|
|
|
and
|
|
<B>jrand48</B>()
|
|
|
|
functions return signed long
|
|
integers uniformly distributed over the interval [-2^31, 2^31).
|
|
<P>
|
|
|
|
The
|
|
<B>srand48</B>(),
|
|
|
|
<B>seed48</B>()
|
|
|
|
and
|
|
<B>lcong48</B>()
|
|
|
|
functions are
|
|
initialization functions, one of which should be called before using
|
|
<B>drand48</B>(),
|
|
|
|
<B>lrand48</B>()
|
|
|
|
or
|
|
<B>mrand48</B>().
|
|
|
|
The functions
|
|
<B>erand48</B>(),
|
|
|
|
<B>nrand48</B>()
|
|
|
|
and
|
|
<B>jrand48</B>()
|
|
|
|
do not require
|
|
an initialization function to be called first.
|
|
<P>
|
|
|
|
All the functions work by generating a sequence of 48-bit integers,
|
|
<I>Xi</I>,
|
|
|
|
according to the linear congruential formula:
|
|
<P>
|
|
|
|
|
|
|
|
<B>Xn+1 = (aXn + c) mod m, where n >= 0</B>
|
|
|
|
|
|
|
|
<P>
|
|
|
|
The parameter
|
|
<I>m</I>
|
|
|
|
= 2^48, hence 48-bit integer arithmetic is performed.
|
|
Unless
|
|
<B>lcong48</B>()
|
|
|
|
is called,
|
|
<I>a</I>
|
|
|
|
and
|
|
<I>c</I>
|
|
|
|
are given by:
|
|
<P>
|
|
|
|
|
|
|
|
<B>a = 0x5DEECE66D</B>
|
|
|
|
<B>c = 0xB</B>
|
|
|
|
|
|
|
|
<P>
|
|
|
|
The value returned by any of the functions
|
|
<B>drand48</B>(),
|
|
|
|
<B>erand48</B>(),
|
|
|
|
<B>lrand48</B>(),
|
|
|
|
<B>nrand48</B>(),
|
|
|
|
<B>mrand48</B>()
|
|
|
|
or
|
|
<B>jrand48</B>()
|
|
|
|
is
|
|
computed by first generating the next 48-bit
|
|
<I>Xi</I>
|
|
|
|
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
|
|
<I>Xi</I>
|
|
|
|
and transformed
|
|
into the returned value.
|
|
<P>
|
|
|
|
The functions
|
|
<B>drand48</B>(),
|
|
|
|
<B>lrand48</B>()
|
|
|
|
and
|
|
<B>mrand48</B>()
|
|
|
|
store
|
|
the last 48-bit
|
|
<I>Xi</I>
|
|
|
|
generated in an internal buffer.
|
|
The functions
|
|
<B>erand48</B>(),
|
|
|
|
<B>nrand48</B>()
|
|
|
|
and
|
|
<B>jrand48</B>()
|
|
|
|
require the calling
|
|
program to provide storage for the successive
|
|
<I>Xi</I>
|
|
|
|
values in the array
|
|
argument
|
|
<I>xsubi</I>.
|
|
|
|
The functions are initialized by placing the initial
|
|
value of
|
|
<I>Xi</I>
|
|
|
|
into the array before calling the function for the first
|
|
time.
|
|
<P>
|
|
|
|
The initializer function
|
|
<B>srand48</B>()
|
|
|
|
sets the high order 32-bits of
|
|
<I>Xi</I>
|
|
|
|
to the argument
|
|
<I>seedval</I>.
|
|
|
|
The low order 16-bits are set
|
|
to the arbitrary value 0x330E.
|
|
<P>
|
|
|
|
The initializer function
|
|
<B>seed48</B>()
|
|
|
|
sets the value of
|
|
<I>Xi</I>
|
|
|
|
to
|
|
the 48-bit value specified in the array argument
|
|
<I>seed16v</I>.
|
|
|
|
The
|
|
previous value of
|
|
<I>Xi</I>
|
|
|
|
is copied into an internal buffer and a
|
|
pointer to this buffer is returned by
|
|
<B>seed48</B>().
|
|
|
|
<P>
|
|
|
|
The initialization function
|
|
<B>lcong48</B>()
|
|
|
|
allows the user to specify
|
|
initial values for
|
|
<I>Xi</I>,
|
|
|
|
<I>a</I>
|
|
|
|
and
|
|
<I>c</I>.
|
|
|
|
Array argument
|
|
elements
|
|
<I>param[0-2]</I>
|
|
|
|
specify
|
|
<I>Xi</I>,
|
|
|
|
<I>param[3-5]</I>
|
|
|
|
specify
|
|
<I>a</I>,
|
|
|
|
and
|
|
<I>param[6]</I>
|
|
|
|
specifies
|
|
<I>c</I>.
|
|
|
|
After
|
|
<B>lcong48</B>()
|
|
|
|
has been called, a subsequent call to either
|
|
<B>srand48</B>()
|
|
|
|
or
|
|
<B>seed48</B>()
|
|
|
|
will restore the standard values of
|
|
<I>a</I>
|
|
|
|
and
|
|
<I>c</I>.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>drand48</B>(),
|
|
|
|
<B>erand48</B>(),
|
|
|
|
<B>lrand48</B>(),
|
|
|
|
<B>nrand48</B>(),
|
|
|
|
<B>mrand48</B>(),
|
|
|
|
<B>jrand48</B>(),
|
|
|
|
<B>srand48</B>(),
|
|
|
|
<B>seed48</B>(),
|
|
|
|
<B>lcong48</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
MT-Unsafe race:drand48
|
|
<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
|
|
<P>
|
|
|
|
The above
|
|
functions record global state information for the random number generator,
|
|
so they are not thread-safe.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+rand">rand</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+random">random</A></B>(3)
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">ATTRIBUTES</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">CONFORMING TO</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">SEE ALSO</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:39 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|