The Rand structure provides a simple random number generator as described
in Larry Paulson in ML for the Working Programmer (pp. 170-171).
The original algorithm was recommended by Park and Miller in
Random number generators: good ones
are hard to find, CACM 1988 (pp 1192-1201) with modifications described
in CACM 1993 (pp. 105-110).
Synopsis
signature RAND
structure Rand : RAND
Interface
type rand = Word.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
Description
type rand = Word.word-
The "state" of the generator, which is just a single word.
val randMin : rand-
The minimum allowed value for the state.
val randMax : rand-
The maximum allowed value for the state.
val random : rand -> rand-
random seedreturns a pseudo-random value in the range[randMin .. randMax]. Iteratively using the value returned byrandomas the next seed will produce a sequence of pseudo-random numbers. val mkRandom : rand -> unit -> rand-
mkRandom seedreturns a function that generates a fresh random number in the range[randMin .. randMax]. val norm : rand -> real-
norm randmaps the random number in the range[randMin .. randMax]to the real interval(0..1). val range : (int * int) -> rand -> int-
range (lo, hi) randmaps the random number in the range[randMin .. randMax]to the interval[lo..hi]. This function will raise theFailexception ifhi < lo.
Bugs
This implementation needs to be updated for 64-bit systems.