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 2014-09-21 "" "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:
73 _SVID_SOURCE || _XOPEN_SOURCE
76 These functions generate pseudo-random numbers using the linear congruential
77 algorithm and 48-bit integer arithmetic.
83 functions return nonnegative
84 double-precision floating-point values uniformly distributed between
91 functions return nonnegative
92 long integers uniformly distributed between 0 and 2^31.
98 functions return signed long
99 integers uniformly distributed between \-2^31 and 2^31.
107 initialization functions, one of which should be called before using
118 an initialization function to be called first.
120 All the functions work by generating a sequence of 48-bit integers,
122 according to the linear congruential formula:
126 .B Xn+1 = (aXn + c) mod m, where n >= 0
132 = 2^48, hence 48-bit integer arithmetic is performed.
148 The value returned by any of the functions
157 computed by first generating the next 48-bit
160 Then the appropriate number of bits, according to the type of data item to
161 be returned, is copied from the high-order bits of
164 into the returned value.
174 generated in an internal buffer.
181 program to provide storage for the successive
186 The functions are initialized by placing the initial
189 into the array before calling the function for the first
192 The initializer function
194 sets the high order 32-bits of
198 The low order 16-bits are set
199 to the arbitrary value 0x330E.
201 The initializer function
206 the 48-bit value specified in the array argument
211 is copied into an internal buffer and a
212 pointer to this buffer is returned by
215 The initialization function
217 allows the user to specify
237 has been called, a subsequent call to either
241 will restore the standard values of
246 .SS Multithreading (see pthreads(7))
258 functions record global state information for the random number generator,
259 so they are not thread-safe.
266 This page is part of release 3.78 of the Linux
269 A description of the project,
270 information about reporting bugs,
271 and the latest version of this page,
273 \%http://www.kernel.org/doc/man\-pages/.