MIT Scheme provides a facility for generating pseudo-random numbers. The current implementation is a ``subtract-with-carry'' random-number generator, based on the algorithm from A New Class of Random Number Generators, George Marsaglia and Arif Zaman, The Annals of Applied Probability, Vol. 1, No. 3, 1991. At the time it was implemented, this was a good algorithm for general purposes, but the state of the art in random-number generation is constantly changing. If necessary, the implementation will be updated to use a new algorithm while retaining the same interface.
The interface described here is essentially identical to that of Common Lisp.
random returns a
pseudo-random number between zero (inclusive) and modulus
(exclusive). The exactness of the returned number is the same as the
exactness of modulus. Additionally, if modulus is an exact
integer, the returned number will be also. Usually, modulus is
either an exact integer or an inexact real; the current implementation
has been tuned to make these two cases fast.
If state is given and not #f, it must be a random-state
object; otherwise, it defaults to the value of the variable
*random-state*. This object is used to maintain the state of the
pseudo-random-number generator and is altered as a side effect of the
random procedure.
(random 1.0) => .32744744667719056 (random 1.0) => .01668326768172354 (random 10) => 3 (random 10) => 8 (random 100) => 38 (random 100) => 63 (random 100/3) => 130501475769920525/6755399441055744 (random 100/3) => 170571694016427575/13510798882111488
random uses by default. A call to random will perform a
side effect on this data structure. This variable may be changed, using
set! or fluid-let, to hold a new random-state object.
*random-state*, or as the state
argument to random. If state is not given or #f,
make-random-state returns a copy of the current
random-number state object (the value of the variable
*random-state*). If state is a random-state object, a copy
of that object is returned. If state is #t, then a new
random-state object is returned that has been ``randomly'' initialized
by some means (such as by a time-of-day clock).
#t if object is a random-state object, otherwise
returns #f.