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