Rand
structure
signature RAND
structure Rand
: RAND
The Rand structure implements a simple linear congruential random number generator with a uniform distribution. It is based on the one described in Paulson's book (pp. 170-171), which is derived from the article ``Random number generators: good ones are hard to find,'' by Stephen K. Park and Keith W. Miller, CACM 31 (1988), pp. 1192-1201. It also incorporates the changes suggested by Park and Miller in CACM 36 (1993), pp. 105-110. The generator has period 2^{(31)}-1. The values returned by random
and mkRandom
are 31-bit words in the range [randMin
,randMax
]. In the current implementation, randMin
is 1.0 and randMax
is 2^{(31)}-2.
type rand = Word31.word
val randMin : rand
val randMax : rand
val random : rand -> rand
val mkRandom : rand -> unit -> rand
val norm : rand -> real
val range : (int * int) -> rand -> int
type rand
randMin
randMax
random
and mkRandom
.
random r
randMin
,randMax
] using the seed r. Iteratively using the value returned by random
as the next seed to random
will produce a sequence of pseudo-random numbers.
mkRandom r
randMin
,randMax
], starting from the seed r.
val norm
randMin
,randMax
] to the range (0.0,1.0). This can be used in combination with random
or mkRandom
to generate normalized real-valued random numbers.
range (i, j)
randMin
,randMax
] uniformly to the range [i,j]. This can be used in combination with random
or mkRandom
to generate random numbers in a given integer range. This raises the exception Fail if j < i.
Random
Last Modified May 6, 1998
Comments to John Reppy
Copyright © 1998 Bell Labs, Lucent Technologies