diff options
author | Aaron Campbell <aaron@cvs.openbsd.org> | 2000-04-20 13:50:04 +0000 |
---|---|---|
committer | Aaron Campbell <aaron@cvs.openbsd.org> | 2000-04-20 13:50:04 +0000 |
commit | ba6b056376adedc82f4ac0f41b5eed2fa3f30c75 (patch) | |
tree | e5c095a3d4f9afb3b98cca651e27f12c8880ffbd /lib/libc/stdlib/rand48.3 | |
parent | 51643f419480d5bdfbed4ef6c16cf20340d8a357 (diff) |
Flesh out stdlib function man pages.
Diffstat (limited to 'lib/libc/stdlib/rand48.3')
-rw-r--r-- | lib/libc/stdlib/rand48.3 | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/libc/stdlib/rand48.3 b/lib/libc/stdlib/rand48.3 index 3d8d53862d4..886e5273d9e 100644 --- a/lib/libc/stdlib/rand48.3 +++ b/lib/libc/stdlib/rand48.3 @@ -9,7 +9,7 @@ .\" of any kind. I shall in no event be liable for anything that happens .\" to anyone/anything when using this software. .\" -.\" $OpenBSD: rand48.3,v 1.6 1999/09/27 02:00:13 aaron Exp $ +.\" $OpenBSD: rand48.3,v 1.7 2000/04/20 13:50:02 aaron Exp $ .\" .Dd October 8, 1993 .Dt RAND48 3 @@ -49,12 +49,13 @@ The .Fn rand48 family of functions generates pseudo-random numbers using a linear -congruential algorithm working on integers 48 bits in size. The -particular formula employed is +congruential algorithm working on integers 48 bits in size. +The particular formula employed is r(n+1) = (a * r(n) + c) mod m where the default values are for the multiplicand a = 0xfdeece66d = 25214903917 and -the addend c = 0xb = 11. The modulus is always fixed at m = 2 ** 48. +the addend c = 0xb = 11. +The modulus is always fixed at m = 2 ** 48. r(n) is called the seed of the random number generator. .Pp 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. .Fn drand48 and .Fn erand48 -return values of type double. The full 48 bits of r(n+1) are +return values of type double. +The full 48 bits of r(n+1) are loaded into the mantissa of the returned value, with the exponent set such that the values produced lie in the interval [0.0, 1.0). .Pp @@ -71,7 +73,8 @@ such that the values produced lie in the interval [0.0, 1.0). and .Fn nrand48 return values of type long in the range -[0, 2**31-1]. The high-order (31) bits of +[0, 2**31-1]. +The high-order (31) bits of r(n+1) are loaded into the lower bits of the returned value, with the topmost (sign) bit set to zero. .Pp @@ -79,14 +82,15 @@ the topmost (sign) bit set to zero. and .Fn jrand48 return values of type long in the range -[-2**31, 2**31-1]. The high-order (32) bits of -r(n+1) are loaded into the returned value. +[-2**31, 2**31-1]. +The high-order (32) bits of r(n+1) are loaded into the returned value. .Pp .Fn drand48 , .Fn lrand48 , and .Fn mrand48 -use an internal buffer to store r(n). For these functions +use an internal buffer to store r(n). +For these functions the initial value of r(0) = 0x1234abcd330e = 20017429951246. .Pp On the other hand, @@ -118,8 +122,8 @@ also initializes the internal buffer r(n) of and .Fn mrand48 , but here all 48 bits of the seed can be specified in an array of 3 shorts, -where the zeroth member specifies the lowest bits. Again, -the constant multiplicand and addend of the algorithm are +where the zeroth member specifies the lowest bits. +Again, the constant multiplicand and addend of the algorithm are reset to the default values given above. .Fn seed48 returns a pointer to an array of 3 shorts which contains the old seed. |