User Tools


Variable *RANDOM-STATE*

Value Type

Initial Value

Description

The current random state, which is used, for example, by the function random when a random state is not explicitly supplied.

Examples

(random-state-p *random-state*)

true

In the example below, the series from any given point is random, but if you backtrack to that point, you get the same series.

(defparameter *snapshot* (make-random-state))

*SNAPSHOT*

(list (loop for i from 1 to 10 collect (random)) (let ((*random-state* *snapshot*)) (loop for i from 1 to 10 collect (random))) (loop for i from 1 to 10 collect (random)) (let ((*random-state* *snapshot*)) (loop for i from 1 to 10 collect (random))))

((19 16 44 19 96 15 76 96 13 61) (19 16 44 19 96 15 76 96 13 61) (16 67 0 43 70 79 58 5 63 50) (16 67 0 43 70 79 58 5 63 50))

Affected By

See Also

Notes

Binding *random-state* to a different random state object correctly saves and restores the old random state object.