The Science Collection provides additional functionality to the Racket implementation of SRFI 27 by Sabastian Egner, which, in turn, is a 54-bit implementation of Pierre L’Ecuyer’s MRG32k3a pseudo-random number generator.

The functions described in this chapter are defined in the "random-source.rkt" file in the Science Collection and are made available using the form:

6.1The SRFI 27 Specification

The following functions are defined in the SRFI specification and are, in purn, provided by the random-source module. The contract shows here are for documentation purposes only–the Racket implementation of SRFI does not define contracts for its functions.

Returns the next integer in {0, ..., n - 1} obtained from the default-random-source. Subsequent results of this function appear to be independent uniformly distributed over the range {0, ..., n - 1}. The argument n must be a positive integer, ptherwise an error is signaled.

Creates a new random source. A random source created with make-random-source represents a deterministic stream of random bits. Each random stream obtained as make-random-source generates the same stream of values unless the state is modified with one of the functions below.

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, indexed by two integers. In contract to random-source-randomize!, this procedure is entirely deterministic.

Returns a procedure to generate random integers using the random source s. The resulting argument takes a single argument n, which must be a positive integer, and returns the next independent uniformly distributed integer from the interval {0, ..., n - 1} by advancing the state of the random source s.

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).

6.2Additional Random Number Functionality

The Science Collection provides additional functionality to that provided by SRFI 27.

The main additional functionality is to define a parameter, current-random-source, that provides a separate random source reference for each thread. The default value for this random source reference is default-random-source.

Returns the next integer in {0, ..., n - 1} obtained from the random source s or (current-random-source) if s is not specified. Subsequent results of this function appear to be independently uniformly distributed over the range {0, ..., n - 1}. The argument n must be a positive integer.

Returns the next number x, 0 < x < 1, obtained from the random source s or (current-random-source) if s is not specified. Subsequent results of this function appear to be independently uniformly distributed.

6.2.3Miscellaneous Functions

These functions provide an alternative set of functions to get or set the state of a random-state. These functions match the conventions for structures in Racket.