std-make-random-state | ![]() ![]() |
(std-make-random-state <state>)
Used to set and restore a unique start-point and method for the pseudo random number generator.
Initialize a fresh random state with T, get the actual random-state with nil, or set a previous random state object with a <state> argument which must satisfy (STD-RANDOM-STATE-P
)
The state object holds the seed value, the method used by std-random and possoibly some other parameters.
The returned state object may be a internal VL object (currently of type _LPPTYPE
) or a named list whose car is eq to :RANDOM-STATE
.
The type of the <state> argument may be as below:
(:RANDOM-STATE method seed [modulo accumulator incrementor])
The defined methods are stored in the list *RANDOM-FUNCS*. You may use your own generator if it returns a number between 0.0 and 1.0.
Defined methods are of type function:
std-%sys-rand
on VL: the system supplied generator. The fastest but not really random.
std-%mult-rand
: So far the best, and quite fast.
std-%mod-rand
: The simple linear congruential generator but with user definable parameters.
See test/randtst.html and test/RANDTST.LSP for more.
The seed value may be either nil, which generates a new seed value or a integer number. If you supply your own method be sure not to exceed the maximal seed value!
You may create a new linear congruential random number generator with user supplied magic numbers on the fly.
(setq state (std-make-random-state T))
; initialize
(std-make-random-state state)
; restore prev
(std-make-random-state nil)
; actual state
(std-make-random-state
'(:random-state std-%sys-rand nil))
; new seed
(std-make-random-state
'(:random-state std-%mult-rand 0))
; old seed
(std-make-random-state '(:random-state std-%mod-rand nil 53125 171 11213))
state: the value which was returned by std-make-random-state, T to initialize or nil for the actual state. Or one of the special lists explained above.
Returns a random-state object, which may be an internal object or a list, which may be used to re-initialize the random number generator.
With non-nil argument changes the state of the pseudo random generator, either the method or the seed. It redefines std-random dynamically. It may reinitialize the seed.
(std-require 'RANDOM)
Defined in RANDOM only