diff options
author | aaron <> | 2000-04-20 13:50:03 +0000 |
---|---|---|
committer | aaron <> | 2000-04-20 13:50:03 +0000 |
commit | a4336f357f9e30dffdfad4909b24bd2e82c096a2 (patch) | |
tree | c79a224a41eb2c48668c4b4eda84163d7daadf64 /src/lib/libc/stdlib/rand48.3 | |
parent | 92b3e44bedaf5a5f85880565a47206cdbf9bfa2a (diff) | |
download | openbsd-a4336f357f9e30dffdfad4909b24bd2e82c096a2.tar.gz openbsd-a4336f357f9e30dffdfad4909b24bd2e82c096a2.tar.bz2 openbsd-a4336f357f9e30dffdfad4909b24bd2e82c096a2.zip |
Flesh out stdlib function man pages.
Diffstat (limited to 'src/lib/libc/stdlib/rand48.3')
-rw-r--r-- | src/lib/libc/stdlib/rand48.3 | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/lib/libc/stdlib/rand48.3 b/src/lib/libc/stdlib/rand48.3 index 3d8d53862d..886e5273d9 100644 --- a/src/lib/libc/stdlib/rand48.3 +++ b/src/lib/libc/stdlib/rand48.3 | |||
@@ -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 | .\" $OpenBSD: rand48.3,v 1.6 1999/09/27 02:00:13 aaron Exp $ | 12 | .\" $OpenBSD: rand48.3,v 1.7 2000/04/20 13:50:02 aaron Exp $ |
13 | .\" | 13 | .\" |
14 | .Dd October 8, 1993 | 14 | .Dd October 8, 1993 |
15 | .Dt RAND48 3 | 15 | .Dt RAND48 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,7 +64,8 @@ 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 |
@@ -71,7 +73,8 @@ such that the values produced lie in the interval [0.0, 1.0). | |||
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,8 +122,8 @@ 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. |