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 2021-03-22 "" "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);
39 .BI "double erand48(unsigned short " xsubi [3]);
41 .B long lrand48(void);
42 .BI "long nrand48(unsigned short " xsubi [3]);
44 .B long mrand48(void);
45 .BI "long jrand48(unsigned short " xsubi [3]);
47 .BI "void srand48(long " seedval );
48 .BI "unsigned short *seed48(unsigned short " seed16v [3]);
49 .BI "void lcong48(unsigned short " param [7]);
53 Feature Test Macro Requirements for glibc (see
54 .BR feature_test_macros (7)):
57 All functions shown above:
69 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
70 || /* Glibc <= 2.19: */ _SVID_SOURCE
73 These functions generate pseudo-random numbers using the linear congruential
74 algorithm and 48-bit integer arithmetic.
80 functions return nonnegative
81 double-precision floating-point values uniformly distributed over the interval
88 functions return nonnegative
89 long integers uniformly distributed over the interval [0,\ 2^31).
95 functions return signed long
96 integers uniformly distributed over the interval [\-2^31,\ 2^31).
104 initialization functions, one of which should be called before using
115 an initialization function to be called first.
117 All the functions work by generating a sequence of 48-bit integers,
119 according to the linear congruential formula:
123 .B Xn+1 = (aXn + c) mod m, where n >= 0
129 = 2^48, hence 48-bit integer arithmetic is performed.
145 The value returned by any of the functions
154 computed by first generating the next 48-bit
157 Then the appropriate number of bits, according to the type of data item to
158 be returned, is copied from the high-order bits of
161 into the returned value.
171 generated in an internal buffer.
178 program to provide storage for the successive
183 The functions are initialized by placing the initial
186 into the array before calling the function for the first
189 The initializer function
191 sets the high order 32-bits of
195 The low order 16-bits are set
196 to the arbitrary value 0x330E.
198 The initializer function
203 the 48-bit value specified in the array argument
208 is copied into an internal buffer and a
209 pointer to this buffer is returned by
212 The initialization function
214 allows the user to specify
234 has been called, a subsequent call to either
238 will restore the standard values of
243 For an explanation of the terms used in this section, see
251 Interface Attribute Value
263 MT-Unsafe race:drand48
271 functions record global state information for the random number generator,
272 so they are not thread-safe.
274 POSIX.1-2001, POSIX.1-2008, SVr4.