2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.\" References consulted:
|
|
|
|
.\" Linux libc source code
|
|
|
|
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
|
|
|
|
.\" 386BSD man pages
|
|
|
|
.\" Modified Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu)
|
|
|
|
.TH DRAND48 3 1993-07-02 "" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
|
|
|
|
lcong48 \- generate uniformly distributed pseudo-random numbers
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <stdlib.h>
|
|
|
|
.sp
|
|
|
|
.B double drand48(void);
|
|
|
|
.sp
|
|
|
|
.BI "double erand48(unsigned short " xsubi [3]);
|
|
|
|
.sp
|
|
|
|
.B long int lrand48(void);
|
|
|
|
.sp
|
|
|
|
.BI "long int nrand48(unsigned short " xsubi [3]);
|
|
|
|
.sp
|
|
|
|
.B long int mrand48(void);
|
|
|
|
.sp
|
|
|
|
.BI "long int jrand48(unsigned short " xsubi [3]);
|
|
|
|
.sp
|
|
|
|
.BI "void srand48(long int " seedval );
|
|
|
|
.sp
|
|
|
|
.BI "unsigned short *seed48(unsigned short " seed16v [3]);
|
|
|
|
.sp
|
|
|
|
.BI "void lcong48(unsigned short " param [7]);
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
These functions generate pseudo-random numbers using the linear congruential
|
|
|
|
algorithm and 48-bit integer arithmetic.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBdrand48\fP() and \fBerand48\fP() functions return non-negative
|
2004-11-03 13:51:07 +00:00
|
|
|
double-precision floating-point values uniformly distributed between
|
|
|
|
[0.0, 1.0).
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBlrand48\fP() and \fBnrand48\fP() functions return non-negative
|
2004-11-03 13:51:07 +00:00
|
|
|
long integers uniformly distributed between 0 and 2^31.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBmrand48\fP() and \fBjrand48\fP() functions return signed long
|
2004-11-03 13:51:07 +00:00
|
|
|
integers uniformly distributed between \-2^31 and 2^31.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The \fBsrand48\fP(), \fBseed48\fP() and \fBlcong48\fP() functions are
|
2004-11-03 13:51:07 +00:00
|
|
|
initialization functions, one of which should be called before using
|
2007-04-12 22:42:49 +00:00
|
|
|
\fBdrand48\fP(), \fBlrand48\fP() or \fBmrand48\fP().
|
|
|
|
The functions
|
2005-10-19 07:07:02 +00:00
|
|
|
\fBerand48\fP(), \fBnrand48\fP() and \fBjrand48\fP() do not require
|
2004-11-03 13:51:07 +00:00
|
|
|
an initialization function to be called first.
|
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
All the functions work by generating a sequence of 48-bit integers,
|
2004-11-03 13:51:07 +00:00
|
|
|
\fIXi\fP, according to the linear congruential formula:
|
|
|
|
.sp
|
|
|
|
.nf
|
|
|
|
.RS
|
|
|
|
.B Xn+1 = (aXn + c) mod m, where n >= 0
|
|
|
|
.RE
|
|
|
|
.fi
|
|
|
|
.sp
|
|
|
|
The parameter \fIm\fP = 2^48, hence 48-bit integer arithmetic is performed.
|
2005-10-19 07:07:02 +00:00
|
|
|
Unless \fBlcong48\fP() is called, \fIa\fP and \fIc\fP are given by:
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
|
|
|
.nf
|
|
|
|
.RS
|
|
|
|
.B a = 0x5DEECE66D
|
|
|
|
.B c = 0xB
|
|
|
|
.RE
|
|
|
|
.fi
|
|
|
|
.sp
|
2005-10-19 07:07:02 +00:00
|
|
|
The value returned by any of the functions \fBdrand48\fP(), \fBerand48\fP(),
|
|
|
|
\fBlrand48\fP(), \fBnrand48\fP(), \fBmrand48\fP() or \fBjrand48\fP() is
|
2004-11-03 13:51:07 +00:00
|
|
|
computed by first generating the next 48-bit \fIXi\fP 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 \fIXi\fP and transformed
|
|
|
|
into the returned value.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The functions \fBdrand48\fP(), \fBlrand48\fP() and \fBmrand48\fP() store
|
2007-04-12 22:42:49 +00:00
|
|
|
the last 48-bit \fIXi\fP generated in an internal buffer.
|
|
|
|
The functions
|
2005-10-19 07:07:02 +00:00
|
|
|
\fBerand48\fP(), \fBnrand48\fP() and \fBjrand48\fP() require the calling
|
2004-11-03 13:51:07 +00:00
|
|
|
program to provide storage for the successive \fIXi\fP values in the array
|
2007-04-12 22:42:49 +00:00
|
|
|
argument \fIxsubi\fP.
|
|
|
|
The functions are initialized by placing the initial
|
2004-11-03 13:51:07 +00:00
|
|
|
value of \fIXi\fP into the array before calling the function for the first
|
|
|
|
time.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The initializer function \fBsrand48\fP() sets the high order 32-bits of
|
2007-04-12 22:42:49 +00:00
|
|
|
\fIXi\fP to the argument \fIseedval\fP.
|
|
|
|
The low order 16-bits are set
|
2004-11-03 13:51:07 +00:00
|
|
|
to the arbitrary value 0x330E.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The initializer function \fBseed48\fP() sets the value of \fIXi\fP to
|
2007-04-12 22:42:49 +00:00
|
|
|
the 48-bit value specified in the array argument \fIseed16v\fP.
|
|
|
|
The
|
2004-11-03 13:51:07 +00:00
|
|
|
previous value of \fIXi\fP is copied into an internal buffer and a
|
2005-10-19 07:07:02 +00:00
|
|
|
pointer to this buffer is returned by \fBseed48\fP().
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
The initialization function \fBlcong48\fP() allows the user to specify
|
2007-04-12 22:42:49 +00:00
|
|
|
initial values for \fIXi\fP, \fIa\fP and \fIc\fP.
|
|
|
|
Array argument
|
2004-11-03 13:51:07 +00:00
|
|
|
elements \fIparam[0-2]\fP specify \fIXi\fP, \fIparam[3-5]\fP specify
|
2007-04-12 22:42:49 +00:00
|
|
|
\fIa\fP, and \fIparam[6]\fP specifies \fIc\fP.
|
|
|
|
After \fBlcong48\fP()
|
2005-10-19 07:07:02 +00:00
|
|
|
has been called, a subsequent call to either \fBsrand48\fP() or
|
|
|
|
\fBseed48\fP() will restore the standard values of \fIa\fP and \fIc\fP.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "CONFORMING TO"
|
2006-08-03 13:57:30 +00:00
|
|
|
SVr4, POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
|
|
|
These functions are declared obsolete by SVID 3, which states that
|
2005-10-19 14:16:57 +00:00
|
|
|
.BR rand(3)
|
|
|
|
should be used instead.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR rand (3),
|
|
|
|
.BR random (3)
|