]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/drand48.3
ld.so.8: srcfix
[thirdparty/man-pages.git] / man3 / drand48.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
7.\"
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.
c13182ef 12.\"
fea681da
MK
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
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" References consulted:
26.\" Linux libc source code
27.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28.\" 386BSD man pages
29.\" Modified Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu)
4b8c67d9 30.TH DRAND48 3 2017-09-15 "" "Linux Programmer's Manual"
fea681da
MK
31.SH NAME
32drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
33lcong48 \- generate uniformly distributed pseudo-random numbers
34.SH SYNOPSIS
35.nf
36.B #include <stdlib.h>
68e4db0a 37.PP
fea681da 38.B double drand48(void);
68e4db0a 39.PP
fea681da 40.BI "double erand48(unsigned short " xsubi [3]);
68e4db0a 41.PP
fea681da 42.B long int lrand48(void);
68e4db0a 43.PP
fea681da 44.BI "long int nrand48(unsigned short " xsubi [3]);
68e4db0a 45.PP
fea681da 46.B long int mrand48(void);
68e4db0a 47.PP
fea681da 48.BI "long int jrand48(unsigned short " xsubi [3]);
68e4db0a 49.PP
fea681da 50.BI "void srand48(long int " seedval );
68e4db0a 51.PP
fea681da 52.BI "unsigned short *seed48(unsigned short " seed16v [3]);
68e4db0a 53.PP
fea681da
MK
54.BI "void lcong48(unsigned short " param [7]);
55.fi
68e4db0a 56.PP
cc4615cc
MK
57.in -4n
58Feature Test Macro Requirements for glibc (see
59.BR feature_test_macros (7)):
60.in
68e4db0a 61.PP
cc4615cc 62.ad l
cfc2d88d 63All functions shown above:
cc4615cc
MK
64.\" .BR drand48 (),
65.\" .BR erand48 (),
66.\" .BR lrand48 (),
67.\" .BR nrand48 (),
68.\" .BR mrand48 (),
69.\" .BR jrand48 (),
70.\" .BR srand48 (),
71.\" .BR seed48 (),
72.\" .BR lcong48 ():
2b1b0424
MK
73_XOPEN_SOURCE
74 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
75 || /* Glibc versions <= 2.19: */ _SVID_SOURCE
cc4615cc 76.ad b
fea681da
MK
77.SH DESCRIPTION
78These functions generate pseudo-random numbers using the linear congruential
79algorithm and 48-bit integer arithmetic.
80.PP
60a90ecd
MK
81The
82.BR drand48 ()
83and
84.BR erand48 ()
2fda57bd 85functions return nonnegative
b62ea03a
MK
86double-precision floating-point values uniformly distributed over the interval
87[0.0,\ 1.0).
fea681da 88.PP
60a90ecd
MK
89The
90.BR lrand48 ()
91and
92.BR nrand48 ()
2fda57bd 93functions return nonnegative
b62ea03a 94long integers uniformly distributed over the interval [0,\ 2^31).
fea681da 95.PP
60a90ecd
MK
96The
97.BR mrand48 ()
98and
99.BR jrand48 ()
100functions return signed long
b62ea03a 101integers uniformly distributed over the interval [\-2^31,\ 2^31).
fea681da 102.PP
60a90ecd
MK
103The
104.BR srand48 (),
105.BR seed48 ()
106and
107.BR lcong48 ()
108functions are
fea681da 109initialization functions, one of which should be called before using
60a90ecd
MK
110.BR drand48 (),
111.BR lrand48 ()
112or
113.BR mrand48 ().
c13182ef 114The functions
60a90ecd
MK
115.BR erand48 (),
116.BR nrand48 ()
117and
118.BR jrand48 ()
119do not require
fea681da
MK
120an initialization function to be called first.
121.PP
c13182ef 122All the functions work by generating a sequence of 48-bit integers,
c6fa0841
MK
123.IR Xi ,
124according to the linear congruential formula:
ba39b288
MK
125.PP
126.in +4n
127.EX
fea681da 128.B Xn+1 = (aXn + c) mod m, where n >= 0
ba39b288
MK
129.EE
130.in
131.PP
c6fa0841
MK
132The parameter
133.I m
134= 2^48, hence 48-bit integer arithmetic is performed.
60a90ecd
MK
135Unless
136.BR lcong48 ()
c6fa0841 137is called,
51700fd7 138.IR a
c6fa0841
MK
139and
140.I c
141are given by:
ba39b288
MK
142.PP
143.in +4n
144.EX
fea681da
MK
145.B a = 0x5DEECE66D
146.B c = 0xB
ba39b288
MK
147.EE
148.in
149.PP
60a90ecd
MK
150The value returned by any of the functions
151.BR drand48 (),
152.BR erand48 (),
153.BR lrand48 (),
154.BR nrand48 (),
155.BR mrand48 ()
156or
157.BR jrand48 ()
158is
c6fa0841
MK
159computed by first generating the next 48-bit
160.I Xi
161in the sequence.
fea681da 162Then the appropriate number of bits, according to the type of data item to
c6fa0841
MK
163be returned, is copied from the high-order bits of
164.I Xi
165and transformed
fea681da
MK
166into the returned value.
167.PP
60a90ecd
MK
168The functions
169.BR drand48 (),
170.BR lrand48 ()
171and
172.BR mrand48 ()
173store
c6fa0841
MK
174the last 48-bit
175.I Xi
176generated in an internal buffer.
c13182ef 177The functions
60a90ecd
MK
178.BR erand48 (),
179.BR nrand48 ()
180and
181.BR jrand48 ()
182require the calling
c6fa0841
MK
183program to provide storage for the successive
184.I Xi
185values in the array
186argument
187.IR xsubi .
c13182ef 188The functions are initialized by placing the initial
c6fa0841
MK
189value of
190.I Xi
191into the array before calling the function for the first
fea681da
MK
192time.
193.PP
60a90ecd
MK
194The initializer function
195.BR srand48 ()
196sets the high order 32-bits of
c6fa0841
MK
197.I Xi
198to the argument
199.IR seedval .
c13182ef 200The low order 16-bits are set
fea681da
MK
201to the arbitrary value 0x330E.
202.PP
60a90ecd
MK
203The initializer function
204.BR seed48 ()
c6fa0841
MK
205sets the value of
206.I Xi
207to
208the 48-bit value specified in the array argument
209.IR seed16v .
c13182ef 210The
c6fa0841
MK
211previous value of
212.I Xi
213is copied into an internal buffer and a
60a90ecd
MK
214pointer to this buffer is returned by
215.BR seed48 ().
fea681da 216.PP
60a90ecd
MK
217The initialization function
218.BR lcong48 ()
219allows the user to specify
c6fa0841
MK
220initial values for
221.IR Xi ,
222.I a
223and
224.IR c .
c13182ef 225Array argument
c6fa0841 226elements
9bc87ed0 227.I param[0\-2]
c6fa0841
MK
228specify
229.IR Xi ,
9bc87ed0 230.I param[3\-5]
c6fa0841
MK
231specify
232.IR a ,
51700fd7 233and
c6fa0841
MK
234.I param[6]
235specifies
236.IR c .
60a90ecd
MK
237After
238.BR lcong48 ()
239has been called, a subsequent call to either
240.BR srand48 ()
241or
242.BR seed48 ()
c6fa0841
MK
243will restore the standard values of
244.I a
245and
246.IR c .
ba368065 247.SH ATTRIBUTES
485507b7
MK
248For an explanation of the terms used in this section, see
249.BR attributes (7).
250.ad l
251.TS
252allbox;
253lb lb lb
d059a452 254lw21 l lw22.
485507b7
MK
255Interface Attribute Value
256T{
ba368065
PH
257.BR drand48 (),
258.BR erand48 (),
259.BR lrand48 (),
260.BR nrand48 (),
261.BR mrand48 (),
262.BR jrand48 (),
263.BR srand48 (),
264.BR seed48 (),
ba368065 265.BR lcong48 ()
485507b7 266T} Thread safety T{
c6e2ef68 267MT-Unsafe race:drand48
485507b7
MK
268T}
269.TE
270.ad
271.PP
272The above
974afcfe 273functions record global state information for the random number generator,
ba368065 274so they are not thread-safe.
47297adb 275.SH CONFORMING TO
6c64e4a5 276POSIX.1-2001, POSIX.1-2008, SVr4.
47297adb 277.SH SEE ALSO
fea681da
MK
278.BR rand (3),
279.BR random (3)