OSDN Git Service

(split) LDP: Change Makefile to stamp-based compilation
[linuxjm/LDP_man-pages.git] / original / man3 / drand48.3
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  2007-07-26 "" "Linux Programmer's Manual"
31 .SH NAME
32 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
33 lcong48 \- generate uniformly distributed pseudo-random numbers
34 .SH SYNOPSIS
35 .nf
36 .B #include <stdlib.h>
37 .sp
38 .B double drand48(void);
39 .sp
40 .BI "double erand48(unsigned short " xsubi [3]);
41 .sp
42 .B long int lrand48(void);
43 .sp
44 .BI "long int nrand48(unsigned short " xsubi [3]);
45 .sp
46 .B long int mrand48(void);
47 .sp
48 .BI "long int jrand48(unsigned short " xsubi [3]);
49 .sp
50 .BI "void srand48(long int " seedval );
51 .sp
52 .BI "unsigned short *seed48(unsigned short " seed16v [3]);
53 .sp
54 .BI "void lcong48(unsigned short " param [7]);
55 .fi
56 .sp
57 .in -4n
58 Feature Test Macro Requirements for glibc (see
59 .BR feature_test_macros (7)):
60 .in
61 .sp
62 .ad l
63 All 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 _SVID_SOURCE || _XOPEN_SOURCE
74 .ad b
75 .SH DESCRIPTION
76 These functions generate pseudo-random numbers using the linear congruential
77 algorithm and 48-bit integer arithmetic.
78 .PP
79 The
80 .BR drand48 ()
81 and
82 .BR erand48 ()
83 functions return nonnegative
84 double-precision floating-point values uniformly distributed between
85 [0.0, 1.0).
86 .PP
87 The
88 .BR lrand48 ()
89 and
90 .BR nrand48 ()
91 functions return nonnegative
92 long integers uniformly distributed between 0 and 2^31.
93 .PP
94 The
95 .BR mrand48 ()
96 and
97 .BR jrand48 ()
98 functions return signed long
99 integers uniformly distributed between \-2^31 and 2^31.
100 .PP
101 The
102 .BR srand48 (),
103 .BR seed48 ()
104 and
105 .BR lcong48 ()
106 functions are
107 initialization functions, one of which should be called before using
108 .BR drand48 (),
109 .BR lrand48 ()
110 or
111 .BR mrand48 ().
112 The functions
113 .BR erand48 (),
114 .BR nrand48 ()
115 and
116 .BR jrand48 ()
117 do not require
118 an initialization function to be called first.
119 .PP
120 All the functions work by generating a sequence of 48-bit integers,
121 \fIXi\fP, according to the linear congruential formula:
122 .sp
123 .nf
124 .RS
125 .B Xn+1 = (aXn + c) mod m,   where n >= 0
126 .RE
127 .fi
128 .sp
129 The parameter \fIm\fP = 2^48, hence 48-bit integer arithmetic is performed.
130 Unless
131 .BR lcong48 ()
132 is called, \fIa\fP and \fIc\fP are given by:
133 .sp
134 .nf
135 .RS
136 .B a = 0x5DEECE66D
137 .B c = 0xB
138 .RE
139 .fi
140 .sp
141 The value returned by any of the functions
142 .BR drand48 (),
143 .BR erand48 (),
144 .BR lrand48 (),
145 .BR nrand48 (),
146 .BR mrand48 ()
147 or
148 .BR jrand48 ()
149 is
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.
154 .PP
155 The functions
156 .BR drand48 (),
157 .BR lrand48 ()
158 and
159 .BR mrand48 ()
160 store
161 the last 48-bit \fIXi\fP generated in an internal buffer.
162 The functions
163 .BR erand48 (),
164 .BR nrand48 ()
165 and
166 .BR jrand48 ()
167 require the calling
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
172 time.
173 .PP
174 The initializer function
175 .BR srand48 ()
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.
180 .PP
181 The initializer function
182 .BR seed48 ()
183 sets the value of \fIXi\fP to
184 the 48-bit value specified in the array argument \fIseed16v\fP.
185 The
186 previous value of \fIXi\fP is copied into an internal buffer and a
187 pointer to this buffer is returned by
188 .BR seed48 ().
189 .PP
190 The initialization function
191 .BR lcong48 ()
192 allows the user to specify
193 initial values for \fIXi\fP, \fIa\fP and \fIc\fP.
194 Array argument
195 elements \fIparam[0-2]\fP specify \fIXi\fP, \fIparam[3-5]\fP specify
196 \fIa\fP, and \fIparam[6]\fP specifies \fIc\fP.
197 After
198 .BR lcong48 ()
199 has been called, a subsequent call to either
200 .BR srand48 ()
201 or
202 .BR seed48 ()
203 will restore the standard values of \fIa\fP and \fIc\fP.
204 .SH CONFORMING TO
205 SVr4, POSIX.1-2001.
206 .SH NOTES
207 These functions are declared obsolete by SVID 3, which states that
208 .BR rand (3)
209 should be used instead.
210 .SH SEE ALSO
211 .BR rand (3),
212 .BR random (3)