1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" Modified Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu)
10 .TH DRAND48 3 2021-03-22 GNU "Linux Programmer's Manual"
12 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
13 lcong48 \- generate uniformly distributed pseudo-random numbers
16 .RI ( libc ", " \-lc )
19 .B #include <stdlib.h>
21 .B double drand48(void);
22 .BI "double erand48(unsigned short " xsubi [3]);
24 .B long lrand48(void);
25 .BI "long nrand48(unsigned short " xsubi [3]);
27 .B long mrand48(void);
28 .BI "long jrand48(unsigned short " xsubi [3]);
30 .BI "void srand48(long " seedval );
31 .BI "unsigned short *seed48(unsigned short " seed16v [3]);
32 .BI "void lcong48(unsigned short " param [7]);
36 Feature Test Macro Requirements for glibc (see
37 .BR feature_test_macros (7)):
40 All functions shown above:
52 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
53 || /* Glibc <= 2.19: */ _SVID_SOURCE
56 These functions generate pseudo-random numbers using the linear congruential
57 algorithm and 48-bit integer arithmetic.
63 functions return nonnegative
64 double-precision floating-point values uniformly distributed over the interval
71 functions return nonnegative
72 long integers uniformly distributed over the interval [0,\ 2^31).
78 functions return signed long
79 integers uniformly distributed over the interval [\-2^31,\ 2^31).
87 initialization functions, one of which should be called before using
98 an initialization function to be called first.
100 All the functions work by generating a sequence of 48-bit integers,
102 according to the linear congruential formula:
106 .B Xn+1 = (aXn + c) mod m, where n >= 0
112 = 2^48, hence 48-bit integer arithmetic is performed.
128 The value returned by any of the functions
137 computed by first generating the next 48-bit
140 Then the appropriate number of bits, according to the type of data item to
141 be returned, is copied from the high-order bits of
144 into the returned value.
154 generated in an internal buffer.
161 program to provide storage for the successive
166 The functions are initialized by placing the initial
169 into the array before calling the function for the first
172 The initializer function
174 sets the high order 32-bits of
178 The low order 16-bits are set
179 to the arbitrary value 0x330E.
181 The initializer function
186 the 48-bit value specified in the array argument
191 is copied into an internal buffer and a
192 pointer to this buffer is returned by
195 The initialization function
197 allows the user to specify
217 has been called, a subsequent call to either
221 will restore the standard values of
226 For an explanation of the terms used in this section, see
234 Interface Attribute Value
246 MT-Unsafe race:drand48
254 functions record global state information for the random number generator,
255 so they are not thread-safe.
257 POSIX.1-2001, POSIX.1-2008, SVr4.