|
|
@ -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. |
|
|
|