Random
structure
signature RANDOM
structure Random
:> RANDOM
The Random structure implements a random number generator using a subtract-with-borrow (SWB) generator as described in Marsaglia and Zaman, "A New Class of Random Number Generators," Ann. Applied Prob. 1(3), 1991, pp. 462-480.
The SWB generator is a 31-bit generator with lags 48 and 8. It has period (2^{(1487)} - 2^{(247)})/105 or about 10^{(445)}. Although generally excellent, they act locally like a lagged Fibonacci generator and thus have troubles with the birthday test. To repair this, the implementation provided here incorporates a suggestion of Marsaglia and Zaman, and combines the SWB generator with a linear congruential generator, specifically (48271*a)mod(2^{(31)}-1).
type rand
val rand : (int * int) -> rand
val toString : rand -> string
val fromString : string -> rand
val randInt : rand -> int
val randNat : rand -> int
val randReal : rand -> real
val randRange : (int * int) -> rand -> int
type rand
rand (i, j)
val toString
val fromString
fromString
is only guaranteed to work on the output of toString
, in which case fromString o toString
is the identity function. A string in an incorrect format will cause fromString
to raise the exception.
These functions allow the state of a generator to be saved, in order that the generator can be replicated at a later time.
randInt s
Int.minInt
,Int.maxInt
] based on the information in s. As a side-effect, the function updates the internal state of s.
randNat s
0
,Int.maxInt
] based on the information in s. As a side-effect, the function updates the internal state of s.
randReal s
randRange (i, j) s
Rand
Last Modified May 6, 1998
Comments to John Reppy
Copyright © 1998 Bell Labs, Lucent Technologies