User Tools


Function MAKE-RANDOM-STATE

Syntax

  • make-random-state &optional statenew-state

Arguments and Values

Description

Creates a fresh object of type random-state suitable for use as the value of Variable *RANDOM-STATE*.

If state is a random state object, the new-state is a copy of that object. If state is nil, the new-state is a copy of the current random state. If state is t, the new-state is a fresh random state object that has been randomly initialized by some means.

Examples

(let* ((rs1 (make-random-state nil)) (rs2 (make-random-state t)) (rs3 (make-random-state rs2)) (rs4 nil)) (list (loop for i from 1 to 10 collect (random 100) when (= i 5) do (setf rs4 (make-random-state))) (loop for i from 1 to 10 collect (random 100 rs1)) (loop for i from 1 to 10 collect (random 100 rs2)) (loop for i from 1 to 10 collect (random 100 rs3)) (loop for i from 1 to 10 collect (random 100 rs4))))

((29 25 72 57 55 68 24 35 54 65) (29 25 72 57 55 68 24 35 54 65) (93 85 53 99 58 62 2 23 23 59) (93 85 53 99 58 62 2 23 23 59) (68 24 35 54 65 54 55 50 59 49))

Side Effects

None.

Affected By

None.

Exceptional Situations

Should signal an error of type type-error if state is not a random state, or nil, or t.

See Also

Notes

One important use of make-random-state is to allow the same series of pseudo-random numbers to be generated many times within a single program.