]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/drand48.3
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[thirdparty/man-pages.git] / man3 / drand48.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\" Modified Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu)
28 .TH DRAND48 3 1993-07-02 "" "Linux Programmer's Manual"
29 .SH NAME
30 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
31 lcong48 \- generate uniformly distributed pseudo-random numbers
32 .SH SYNOPSIS
33 .nf
34 .B #include <stdlib.h>
35 .sp
36 .B double drand48(void);
37 .sp
38 .BI "double erand48(unsigned short " xsubi [3]);
39 .sp
40 .B long int lrand48(void);
41 .sp
42 .BI "long int nrand48(unsigned short " xsubi [3]);
43 .sp
44 .B long int mrand48(void);
45 .sp
46 .BI "long int jrand48(unsigned short " xsubi [3]);
47 .sp
48 .BI "void srand48(long int " seedval );
49 .sp
50 .BI "unsigned short *seed48(unsigned short " seed16v [3]);
51 .sp
52 .BI "void lcong48(unsigned short " param [7]);
53 .fi
54 .SH DESCRIPTION
55 These functions generate pseudo-random numbers using the linear congruential
56 algorithm and 48-bit integer arithmetic.
57 .PP
58 The \fBdrand48\fP() and \fBerand48\fP() functions return non-negative
59 double-precision floating-point values uniformly distributed between
60 [0.0, 1.0).
61 .PP
62 The \fBlrand48\fP() and \fBnrand48\fP() functions return non-negative
63 long integers uniformly distributed between 0 and 2^31.
64 .PP
65 The \fBmrand48\fP() and \fBjrand48\fP() functions return signed long
66 integers uniformly distributed between \-2^31 and 2^31.
67 .PP
68 The \fBsrand48\fP(), \fBseed48\fP() and \fBlcong48\fP() functions are
69 initialization functions, one of which should be called before using
70 \fBdrand48\fP(), \fBlrand48\fP() or \fBmrand48\fP().
71 The functions
72 \fBerand48\fP(), \fBnrand48\fP() and \fBjrand48\fP() do not require
73 an initialization function to be called first.
74 .PP
75 All the functions work by generating a sequence of 48-bit integers,
76 \fIXi\fP, according to the linear congruential formula:
77 .sp
78 .nf
79 .RS
80 .B Xn+1 = (aXn + c) mod m, where n >= 0
81 .RE
82 .fi
83 .sp
84 The parameter \fIm\fP = 2^48, hence 48-bit integer arithmetic is performed.
85 Unless \fBlcong48\fP() is called, \fIa\fP and \fIc\fP are given by:
86 .sp
87 .nf
88 .RS
89 .B a = 0x5DEECE66D
90 .B c = 0xB
91 .RE
92 .fi
93 .sp
94 The value returned by any of the functions \fBdrand48\fP(), \fBerand48\fP(),
95 \fBlrand48\fP(), \fBnrand48\fP(), \fBmrand48\fP() or \fBjrand48\fP() is
96 computed by first generating the next 48-bit \fIXi\fP in the sequence.
97 Then the appropriate number of bits, according to the type of data item to
98 be returned, is copied from the high-order bits of \fIXi\fP and transformed
99 into the returned value.
100 .PP
101 The functions \fBdrand48\fP(), \fBlrand48\fP() and \fBmrand48\fP() store
102 the last 48-bit \fIXi\fP generated in an internal buffer.
103 The functions
104 \fBerand48\fP(), \fBnrand48\fP() and \fBjrand48\fP() require the calling
105 program to provide storage for the successive \fIXi\fP values in the array
106 argument \fIxsubi\fP.
107 The functions are initialized by placing the initial
108 value of \fIXi\fP into the array before calling the function for the first
109 time.
110 .PP
111 The initializer function \fBsrand48\fP() sets the high order 32-bits of
112 \fIXi\fP to the argument \fIseedval\fP.
113 The low order 16-bits are set
114 to the arbitrary value 0x330E.
115 .PP
116 The initializer function \fBseed48\fP() sets the value of \fIXi\fP to
117 the 48-bit value specified in the array argument \fIseed16v\fP.
118 The
119 previous value of \fIXi\fP is copied into an internal buffer and a
120 pointer to this buffer is returned by \fBseed48\fP().
121 .PP
122 The initialization function \fBlcong48\fP() allows the user to specify
123 initial values for \fIXi\fP, \fIa\fP and \fIc\fP.
124 Array argument
125 elements \fIparam[0-2]\fP specify \fIXi\fP, \fIparam[3-5]\fP specify
126 \fIa\fP, and \fIparam[6]\fP specifies \fIc\fP.
127 After \fBlcong48\fP()
128 has been called, a subsequent call to either \fBsrand48\fP() or
129 \fBseed48\fP() will restore the standard values of \fIa\fP and \fIc\fP.
130 .SH "CONFORMING TO"
131 SVr4, POSIX.1-2001.
132 .SH NOTES
133 These functions are declared obsolete by SVID 3, which states that
134 .BR rand(3)
135 should be used instead.
136 .SH "SEE ALSO"
137 .BR rand (3),
138 .BR random (3)