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 2007-07-26 "" "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,
121 \fIXi\fP, according to the linear congruential formula:
125 .B Xn+1 = (aXn + c) mod m, where n >= 0
129 The parameter \fIm\fP = 2^48, hence 48-bit integer arithmetic is performed.
132 is called, \fIa\fP and \fIc\fP are given by:
141 The value returned by any of the functions
150 computed by first generating the next 48-bit \fIXi\fP in the sequence.
151 Then the appropriate number of bits, according to the type of data item to
152 be returned, is copied from the high-order bits of \fIXi\fP and transformed
153 into the returned value.
161 the last 48-bit \fIXi\fP generated in an internal buffer.
168 program to provide storage for the successive \fIXi\fP values in the array
169 argument \fIxsubi\fP.
170 The functions are initialized by placing the initial
171 value of \fIXi\fP into the array before calling the function for the first
174 The initializer function
176 sets the high order 32-bits of
177 \fIXi\fP to the argument \fIseedval\fP.
178 The low order 16-bits are set
179 to the arbitrary value 0x330E.
181 The initializer function
183 sets the value of \fIXi\fP to
184 the 48-bit value specified in the array argument \fIseed16v\fP.
186 previous value of \fIXi\fP is copied into an internal buffer and a
187 pointer to this buffer is returned by
190 The initialization function
192 allows the user to specify
193 initial values for \fIXi\fP, \fIa\fP and \fIc\fP.
195 elements \fIparam[0-2]\fP specify \fIXi\fP, \fIparam[3-5]\fP specify
196 \fIa\fP, and \fIparam[6]\fP specifies \fIc\fP.
199 has been called, a subsequent call to either
203 will restore the standard values of \fIa\fP and \fIc\fP.
207 These functions are declared obsolete by SVID 3, which states that
209 should be used instead.