|
From: Tobias C. R. <tc...@fr...> - 2010-02-15 10:16:58
|
Faré <fa...@gm...> writes: > Ahem. I understand that SBCL lives by a strict understanding of the > wording of the standard, and I now realize (a bit too late) it was > preposterous to extend MAKE-RANDOM-STATE when the standard explicitly > says: "Should signal an error of type type-error if state is not a > random state, or nil, or t.". I wish I had had this code review > earlier. > > Here is a patch to restore strict ANSI-ness of MAKE-RANDOM-STATE and > instead export my extended version as SB-EXT:SEED-RANDOM-STATE. > > (It passes compilation and run-tests.sh is an apparent success, which > doesn't say much.) > > Thanks to Xof, nyef, tcr for their feedback, kmp for the CLHS. > > I agree with Scott L. Burson that a notional future version of the > standard should extend this function. But since that version is purely > notional, it may as well have ponies, too. Nyef proposed to extend the arglist which seems not to be disallowed by 1.6 Language Extensions: (make-random-state t :seed <uint32>) I liked that idea better than introducing a new function. AllegroCL seems to do the same albeit their choice of API is &OPTIONAL STATE SEED: The seed argument is provided as an extension to standard Common Lisp. If state is specified as t, and seed is given and is an integer, then instead of using its own internal method for generating a seed, that specified seed is accepted and used to create the new random-state. Two such calls to make-random-state with the same seed will produce equivalent random-states. Only the least significant 32 bits of the integer are used to seed the random state. This capability allows the user to generate starting seeds from any random-number generation source. The question of how long that source requires to generate truly random data is the user's responsibility. (Thus /dev/random, if available, may block indefinitely waiting for the entropy pool to be replenished. /dev/urandom can also be used to generate random seeds, if it is available). http://www.franz.com/support/documentation/8.1/doc/implementation.htm#cl-random-2 -T. |