Next: srfi random design, Previous: srfi random rationale, Up: srfi random [Index]
The next integer x in {0, ..., n-1}
obtained from
default--random--source
. Subsequent results of this procedure
appear to be independent uniformly distributed over the range {0,
..., n-1}
. The argument n must be a positive integer, otherwise
an error is signalled.
The next number 0 < x < 1
obtained from
default-random-source
. Subsequent results of this procedure
appear to be independent uniformly distributed. The numerical type of
the results and the quantization of the output range depend on the
implementation; refer to random-source-make-reals
for details.
A random source from which random-integer
and random-real
have been derived using random-source-make-integers
and
random-source-make-reals
.
Note that an assignment to default-random-source
does not change
the already built random-integer
or random-real
; it is
also strongly recommended not to assign a new value.
Create a new random source s. Implementations may accept
additional, optional arguments in order to create different types of
random sources. A random source created with make-random-source
represents a deterministic stream of random bits generated by some form
of pseudo random number generator. Each random source obtained as
(make-random-source)
generates the same stream of values, unless
the state is modified with one of the procedures below.
Tests if obj is a random source. Objects of type random source are distinct from all other types of objects.
Get and set the current state of a random source s. The structure
of the object state depends on the implementation; the only portable use
of it is as argument to random-source-state-set!
. It is,
however, required that a state possess an external representation.
Makes an effort to set the state of the random source s to a truly random state. The actual quality of this randomization depends on the implementation but it can at least be assumed that the procedure sets s to a different state for each subsequent run of the Scheme system.
Changes the state of the random source s into the initial state of
the (i, j)–th independent random source, where i and
j are non–negative integers. This procedure provides a mechanism
to obtain a large number of independent random sources (usually all
derived from the same backbone generator), indexed by two integers. In
contrast to random-source-randomize!
, this procedure is entirely
deterministic.
Obtains a procedure rand to generate random integers using the
random source s. rand takes a single argument n,
which must be a positive integer, and returns the next uniformly
distributed random integer from the interval {0, ..., n-1}
by
advancing the state of the source s.
If an application obtains and uses several generators for the same random source s, a call to any of these generators advances the state of s. Hence, the generators do not produce the same sequence of random integers each but rather share a state. This also holds for all other types of generators derived from a fixed random source. Implementations that support concurrency make sure that the state of a generator is properly advanced.
Obtains a procedure rand to generate random real numbers 0 <
x < 1
using the random source s. The procedure rand is
called without arguments.
The optional parameter unit determines the type of numbers being
produced by rand and the quantization of the output. unit
must be a number such that 0 < unit < 1
. The numbers created by
rand are of the same numerical type as unit and the potential output
values are spaced by at most unit.
One can imagine rand to create numbers as x*unit
where
x is a random integer in {1, ..., floor(1/unit)-1}
.
Note, however, that this need not be the way the values are actually
created and that the actual resolution of rand can be much higher
than unit. In case unit is absent it defaults to a
reasonably small value (related to the width of the mantissa of an
efficient number format).
Next: srfi random design, Previous: srfi random rationale, Up: srfi random [Index]