1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
29 .\" Modified Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu)
30 .TH DRAND48 3 2017-09-15 "" "Linux Programmer's Manual"
32 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
33 lcong48 \- generate uniformly distributed pseudo-random numbers
36 .B #include <stdlib.h>
38 .B double drand48(void);
40 .BI "double erand48(unsigned short " xsubi [3]);
42 .B long int lrand48(void);
44 .BI "long int nrand48(unsigned short " xsubi [3]);
46 .B long int mrand48(void);
48 .BI "long int jrand48(unsigned short " xsubi [3]);
50 .BI "void srand48(long int " seedval );
52 .BI "unsigned short *seed48(unsigned short " seed16v [3]);
54 .BI "void lcong48(unsigned short " param [7]);
58 Feature Test Macro Requirements for glibc (see
59 .BR feature_test_macros (7)):
63 All functions shown above:
74 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
75 || /* Glibc versions <= 2.19: */ _SVID_SOURCE
78 These functions generate pseudo-random numbers using the linear congruential
79 algorithm and 48-bit integer arithmetic.
85 functions return nonnegative
86 double-precision floating-point values uniformly distributed over the interval
93 functions return nonnegative
94 long integers uniformly distributed over the interval [0,\ 2^31).
100 functions return signed long
101 integers uniformly distributed over the interval [\-2^31,\ 2^31).
109 initialization functions, one of which should be called before using
120 an initialization function to be called first.
122 All the functions work by generating a sequence of 48-bit integers,
124 according to the linear congruential formula:
128 .B Xn+1 = (aXn + c) mod m, where n >= 0
134 = 2^48, hence 48-bit integer arithmetic is performed.
150 The value returned by any of the functions
159 computed by first generating the next 48-bit
162 Then the appropriate number of bits, according to the type of data item to
163 be returned, is copied from the high-order bits of
166 into the returned value.
176 generated in an internal buffer.
183 program to provide storage for the successive
188 The functions are initialized by placing the initial
191 into the array before calling the function for the first
194 The initializer function
196 sets the high order 32-bits of
200 The low order 16-bits are set
201 to the arbitrary value 0x330E.
203 The initializer function
208 the 48-bit value specified in the array argument
213 is copied into an internal buffer and a
214 pointer to this buffer is returned by
217 The initialization function
219 allows the user to specify
239 has been called, a subsequent call to either
243 will restore the standard values of
248 For an explanation of the terms used in this section, see
255 Interface Attribute Value
267 MT-Unsafe race:drand48
273 functions record global state information for the random number generator,
274 so they are not thread-safe.
276 POSIX.1-2001, POSIX.1-2008, SVr4.