Next: , Previous: , Up: random   [Index]


49.4 Randomness sources

Parameter: random-source-maker

Hold a procedure that can be used to generate a new randomness source. It is initialised to make-random-source/mrg32k3a. For example, it can be used as:

(define source  ((random-source-maker)))
(define integer (random-source-integer-maker source))
(display (integer))
-| <a random integer>

and as:

(parameterise ((random-source-maker
                  make-random-source/device))
  (let* ((source  ((random-source-maker)))
         (integer (random-source-integer-maker source)))
    (display (integer))))
-| <a random integer>
Function: random-source? obj

Test if obj is a randomness source. Objects of type randomness source are distinct from all other types of objects.

Function: random-source-state-ref source
Function: random-source-state-set! source state

Get and set the current state of source. The purpose of these functions is to allow saving and restoring the state between sessions (for example, save the state to a file and reload it later).

The state value is always a vector whose first element is a symbol describing the generator. The other elements of the vector depend on the kind of generator: Refer to generator’s documentation for their format.

Function: random-source-seed! source integers-maker

Reseed source to a new state. integers-maker must be a a generator of random integer numbers, like the ones returned by random-source-integers-maker. Notice that many random sources require integer-makers to return integers representable with 32 bits.

Function: random-source-required-seed-values source

When random-source-seed! is used to reseed a source, some generator will invoke integers-maker a fixed and known number of times, other generators will invoke it a configurable number of times, other generators will invoke it until it first returns #f, other generators will invoke it until the returned numbers have some desired property.

This function returns the number of times integers-maker will be called; if the return value is #f: integers-maker will be invoked until it first returns #f; if the return value is infinity: integers-maker will be invoked until it returns numbers with some desired property.

Function: random-source-jumpahead! source number-of-steps

Move ahead number-of-steps randomness source’s state. What this means exactly depends on the type of source.

The following procedures return a closure rand to generate pseudo–random integers and real numbers using a randomness source. If an application obtains and uses several rand procedures for the same randomness source, a call to any of these procedures advances the state of source. Hence, the procedures do not produce the same sequence of random integers each, but rather share a state.

Function: random-source-integers-maker source

Return a procedure rand to generate random integers using source. rand takes a single argument U, which must be a positive integer, and returns the next uniformly distributed random integer X in the interval 0 <= X < U by advancing the state of source.

Function: random-source-reals-maker source
Function: random-source-reals-maker source unit

Return a procedure rand which, when invoked with no arguments, generates random real numbers X in the range 0 < X < 1 using source. X=0 and X=1 are excluded in order to allow \log(X) and \log(1-X) without the danger of a numerical exception.

The optional parameter unit determines the quantization of the output; to have effect, unit must be a number such that 0 < unit < 1, if unit is greater than, or equal to, 1 the generated numbers will have the default unit. The numbers created by rand are spaced by at most unit. Generating real numbers, for details.


Next: , Previous: , Up: random   [Index]