diff options
Diffstat (limited to 'src/lib/libc/stdlib/rand48.3')
-rw-r--r-- | src/lib/libc/stdlib/rand48.3 | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/lib/libc/stdlib/rand48.3 b/src/lib/libc/stdlib/rand48.3 index 5a772c9a8c..78cd0a7cd5 100644 --- a/src/lib/libc/stdlib/rand48.3 +++ b/src/lib/libc/stdlib/rand48.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | \" Copyright (c) 1993 Martin Birgmeier | 1 | .\" Copyright (c) 1993 Martin Birgmeier |
2 | .\" All rights reserved. | 2 | .\" All rights reserved. |
3 | .\" | 3 | .\" |
4 | .\" You may redistribute unmodified or modified versions of this source | 4 | .\" You may redistribute unmodified or modified versions of this source |
@@ -9,7 +9,7 @@ | |||
9 | .\" of any kind. I shall in no event be liable for anything that happens | 9 | .\" of any kind. I shall in no event be liable for anything that happens |
10 | .\" to anyone/anything when using this software. | 10 | .\" to anyone/anything when using this software. |
11 | .\" | 11 | .\" |
12 | .\" $Id: rand48.3,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $ | 12 | .\" $OpenBSD: rand48.3,v 1.10 2003/06/01 19:27:27 jmc Exp $ |
13 | .\" | 13 | .\" |
14 | .Dd October 8, 1993 | 14 | .Dd October 8, 1993 |
15 | .Dt RAND48 3 | 15 | .Dt RAND48 3 |
@@ -24,10 +24,10 @@ | |||
24 | .Nm srand48 , | 24 | .Nm srand48 , |
25 | .Nm seed48 , | 25 | .Nm seed48 , |
26 | .Nm lcong48 | 26 | .Nm lcong48 |
27 | .Nd pseudo random number generators and initialization routines | 27 | .Nd pseudo-random number generators and initialization routines |
28 | .Sh SYNOPSIS | 28 | .Sh SYNOPSIS |
29 | .Fd #include <stdlib.h> | 29 | .Fd #include <stdlib.h> |
30 | .Ft double | 30 | .Ft double |
31 | .Fn drand48 void | 31 | .Fn drand48 void |
32 | .Ft double | 32 | .Ft double |
33 | .Fn erand48 "unsigned short xseed[3]" | 33 | .Fn erand48 "unsigned short xseed[3]" |
@@ -49,12 +49,13 @@ | |||
49 | The | 49 | The |
50 | .Fn rand48 | 50 | .Fn rand48 |
51 | family of functions generates pseudo-random numbers using a linear | 51 | family of functions generates pseudo-random numbers using a linear |
52 | congruential algorithm working on integers 48 bits in size. The | 52 | congruential algorithm working on integers 48 bits in size. |
53 | particular formula employed is | 53 | The particular formula employed is |
54 | r(n+1) = (a * r(n) + c) mod m | 54 | r(n+1) = (a * r(n) + c) mod m |
55 | where the default values are | 55 | where the default values are |
56 | for the multiplicand a = 0xfdeece66d = 25214903917 and | 56 | for the multiplicand a = 0xfdeece66d = 25214903917 and |
57 | the addend c = 0xb = 11. The modulus is always fixed at m = 2 ** 48. | 57 | the addend c = 0xb = 11. |
58 | The modulus is always fixed at m = 2 ** 48. | ||
58 | r(n) is called the seed of the random number generator. | 59 | r(n) is called the seed of the random number generator. |
59 | .Pp | 60 | .Pp |
60 | For all the six generator routines described next, the first | 61 | For all the six generator routines described next, the first |
@@ -63,15 +64,17 @@ computational step is to perform a single iteration of the algorithm. | |||
63 | .Fn drand48 | 64 | .Fn drand48 |
64 | and | 65 | and |
65 | .Fn erand48 | 66 | .Fn erand48 |
66 | return values of type double. The full 48 bits of r(n+1) are | 67 | return values of type double. |
68 | The full 48 bits of r(n+1) are | ||
67 | loaded into the mantissa of the returned value, with the exponent set | 69 | loaded into the mantissa of the returned value, with the exponent set |
68 | such that the values produced lie in the interval [0.0, 1.0). | 70 | such that the values produced lie in the interval [0.0, 1.0]. |
69 | .Pp | 71 | .Pp |
70 | .Fn lrand48 | 72 | .Fn lrand48 |
71 | and | 73 | and |
72 | .Fn nrand48 | 74 | .Fn nrand48 |
73 | return values of type long in the range | 75 | return values of type long in the range |
74 | [0, 2**31-1]. The high-order (31) bits of | 76 | [0, 2**31-1]. |
77 | The high-order (31) bits of | ||
75 | r(n+1) are loaded into the lower bits of the returned value, with | 78 | r(n+1) are loaded into the lower bits of the returned value, with |
76 | the topmost (sign) bit set to zero. | 79 | the topmost (sign) bit set to zero. |
77 | .Pp | 80 | .Pp |
@@ -79,14 +82,15 @@ the topmost (sign) bit set to zero. | |||
79 | and | 82 | and |
80 | .Fn jrand48 | 83 | .Fn jrand48 |
81 | return values of type long in the range | 84 | return values of type long in the range |
82 | [-2**31, 2**31-1]. The high-order (32) bits of | 85 | [-2**31, 2**31-1]. |
83 | r(n+1) are loaded into the returned value. | 86 | The high-order (32) bits of r(n+1) are loaded into the returned value. |
84 | .Pp | 87 | .Pp |
85 | .Fn drand48 , | 88 | .Fn drand48 , |
86 | .Fn lrand48 , | 89 | .Fn lrand48 , |
87 | and | 90 | and |
88 | .Fn mrand48 | 91 | .Fn mrand48 |
89 | use an internal buffer to store r(n). For these functions | 92 | use an internal buffer to store r(n). |
93 | For these functions | ||
90 | the initial value of r(0) = 0x1234abcd330e = 20017429951246. | 94 | the initial value of r(0) = 0x1234abcd330e = 20017429951246. |
91 | .Pp | 95 | .Pp |
92 | On the other hand, | 96 | On the other hand, |
@@ -118,12 +122,12 @@ also initializes the internal buffer r(n) of | |||
118 | and | 122 | and |
119 | .Fn mrand48 , | 123 | .Fn mrand48 , |
120 | but here all 48 bits of the seed can be specified in an array of 3 shorts, | 124 | but here all 48 bits of the seed can be specified in an array of 3 shorts, |
121 | where the zeroth member specifies the lowest bits. Again, | 125 | where the zeroth member specifies the lowest bits. |
122 | the constant multiplicand and addend of the algorithm are | 126 | Again, the constant multiplicand and addend of the algorithm are |
123 | reset to the default values given above. | 127 | reset to the default values given above. |
124 | .Fn seed48 | 128 | .Fn seed48 |
125 | returns a pointer to an array of 3 shorts which contains the old seed. | 129 | returns a pointer to an array of 3 shorts which contains the old seed. |
126 | This array is statically allocated, thus its contents are lost after | 130 | This array is statically allocated, so its contents are lost after |
127 | each new call to | 131 | each new call to |
128 | .Fn seed48 . | 132 | .Fn seed48 . |
129 | .Pp | 133 | .Pp |
@@ -152,9 +156,10 @@ always also set the multiplicand and addend for any of the six | |||
152 | generator calls. | 156 | generator calls. |
153 | .Pp | 157 | .Pp |
154 | For a more powerful random number generator, see | 158 | For a more powerful random number generator, see |
155 | .Xr random 3 | 159 | .Xr random 3 . |
156 | .Sh AUTHOR | ||
157 | Martin Birgmeier | ||
158 | .Sh SEE ALSO | 160 | .Sh SEE ALSO |
161 | .Xr arc4random 3 , | ||
159 | .Xr rand 3 , | 162 | .Xr rand 3 , |
160 | .Xr random 3 . | 163 | .Xr random 3 |
164 | .Sh AUTHORS | ||
165 | Martin Birgmeier | ||