1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" 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.
.\"
.\" 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.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
.\" 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 2016-03-15 "" "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
.sp
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.in
.sp
.ad l
All functions shown above:
.\" .BR drand48 (),
.\" .BR erand48 (),
.\" .BR lrand48 (),
.\" .BR nrand48 (),
.\" .BR mrand48 (),
.\" .BR jrand48 (),
.\" .BR srand48 (),
.\" .BR seed48 (),
.\" .BR lcong48 ():
_XOPEN_SOURCE
|| /* Glibc since 2.19: */ _DEFAULT_SOURCE
|| /* Glibc versions <= 2.19: */ _SVID_SOURCE
.ad b
.SH DESCRIPTION
These functions generate pseudo-random numbers using the linear congruential
algorithm and 48-bit integer arithmetic.
.PP
The
.BR drand48 ()
and
.BR erand48 ()
functions return nonnegative
double-precision floating-point values uniformly distributed over the interval
[0.0,\ 1.0).
.PP
The
.BR lrand48 ()
and
.BR nrand48 ()
functions return nonnegative
long integers uniformly distributed over the interval [0,\ 2^31).
.PP
The
.BR mrand48 ()
and
.BR jrand48 ()
functions return signed long
integers uniformly distributed over the interval [\-2^31,\ 2^31).
.PP
The
.BR srand48 (),
.BR seed48 ()
and
.BR lcong48 ()
functions are
initialization functions, one of which should be called before using
.BR drand48 (),
.BR lrand48 ()
or
.BR mrand48 ().
The functions
.BR erand48 (),
.BR nrand48 ()
and
.BR jrand48 ()
do not require
an initialization function to be called first.
.PP
All the functions work by generating a sequence of 48-bit integers,
.IR Xi ,
according to the linear congruential formula:
.sp
.nf
.RS
.B Xn+1 = (aXn + c) mod m, where n >= 0
.RE
.fi
.sp
The parameter
.I m
= 2^48, hence 48-bit integer arithmetic is performed.
Unless
.BR lcong48 ()
is called,
.IR a
and
.I c
are given by:
.sp
.nf
.RS
.B a = 0x5DEECE66D
.B c = 0xB
.RE
.fi
.sp
The value returned by any of the functions
.BR drand48 (),
.BR erand48 (),
.BR lrand48 (),
.BR nrand48 (),
.BR mrand48 ()
or
.BR jrand48 ()
is
computed by first generating the next 48-bit
.I Xi
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
and transformed
into the returned value.
.PP
The functions
.BR drand48 (),
.BR lrand48 ()
and
.BR mrand48 ()
store
the last 48-bit
.I Xi
generated in an internal buffer.
The functions
.BR erand48 (),
.BR nrand48 ()
and
.BR jrand48 ()
require the calling
program to provide storage for the successive
.I Xi
values in the array
argument
.IR xsubi .
The functions are initialized by placing the initial
value of
.I Xi
into the array before calling the function for the first
time.
.PP
The initializer function
.BR srand48 ()
sets the high order 32-bits of
.I Xi
to the argument
.IR seedval .
The low order 16-bits are set
to the arbitrary value 0x330E.
.PP
The initializer function
.BR seed48 ()
sets the value of
.I Xi
to
the 48-bit value specified in the array argument
.IR seed16v .
The
previous value of
.I Xi
is copied into an internal buffer and a
pointer to this buffer is returned by
.BR seed48 ().
.PP
The initialization function
.BR lcong48 ()
allows the user to specify
initial values for
.IR Xi ,
.I a
and
.IR c .
Array argument
elements
.I param[0-2]
specify
.IR Xi ,
.I param[3-5]
specify
.IR a ,
and
.I param[6]
specifies
.IR c .
After
.BR lcong48 ()
has been called, a subsequent call to either
.BR srand48 ()
or
.BR seed48 ()
will restore the standard values of
.I a
and
.IR c .
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
.ad l
.TS
allbox;
lb lb lb
lw21 l lw22.
Interface Attribute Value
T{
.BR drand48 (),
.BR erand48 (),
.BR lrand48 (),
.BR nrand48 (),
.BR mrand48 (),
.BR jrand48 (),
.BR srand48 (),
.BR seed48 (),
.BR lcong48 ()
T} Thread safety T{
MT-Unsafe race:drand48
T}
.TE
.ad
.PP
The above
functions record global state information for the random number generator,
so they are not thread-safe.
.SH CONFORMING TO
POSIX.1-2001, POSIX.1-2008, SVr4.
.SH SEE ALSO
.BR rand (3),
.BR random (3)
.SH COLOPHON
This page is part of release 4.10 of the Linux
.I man-pages
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
\%https://www.kernel.org/doc/man\-pages/.
|