MIT/GNU 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 very similar to that of Common Lisp.
Modulus must be a positive real number.
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
This object is used to maintain the state of the pseudo-random-number
generator and is altered as a side effect of the
(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
State must be a random-state object.
returns a pseudo-random number between zero inclusive and one exclusive;
the returned number is always a flonum and therefore an inexact real
flo:random-unit is equivalent to
random with a
1.0, except that it is faster.
The next three definitions concern random-state objects. In addition to
these definitions, it is important to know that random-state objects are
specifically designed so that they can be saved to disk using the
fasdump procedure, and later restored using the
procedure. This allows a particular random-state object to be saved in
order to replay a particular pseudo-random sequence.
This variable is deprecated; pass an explicit state instead.
This procedure returns a new random-state object, suitable for use as
as the state argument to
random. If state is not
make-random-state returns a copy of
default-random-source. 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
#t if object is a random-state object, otherwise