This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see RandomnessArcfide in WG2's repo for R7RS-large.


2010-11-01 04:18:41
2Update the Seed.history

Simple Randomness

Aaron Hsu


The following proposal provides a simple, minimal interface to random number generation. It allows both controlled random seeding and also a single procedure that provides randomness. It is designed to be simple and fairly useful.


Randomness is a common feature to use in education and general programming. Therefore, it makes sense to have WG1 standardize randomness to some degree. The current proposals on the table are either too complex or do not provide the necessary features. Specifically, when teaching about randomness, it is important to be able to control the way that randomness falls out when grading assignments or testing them.


(random real)
Returns a random value in the range [0.0, real). When given an exact integer, the values returned must be exact integers; otherwise it will return a real value.
A parameter like procedure that allows the seed to be set and accessed. The procedure may be passed a single non-negative exact integer to set a specific seed, and this must be supported on all Schemes, but Schemes may optionally support different seed values.

Design Rationale

I do not see any reason to have two procedures for getting a random value. These can be combined into one without requiring much trouble. Additionally, this one procedure is more general than the two procedures suggested by RandomCowan. It is also more simple than SRFI-27. The possibility of returning a 0.0 value from random is intentional to make the procedure behave in a more consistent manner. This should not be a problem, as suggested by RandomCowan, with log if (log 0.0) is defined to return -inf.0.