Re: Random generator
Gary Byers <[email protected]> Mon, 17 Sep 2007 06:33:09 -0600 (MDT)
| Newsgroups | gmane.lisp.openmcl.bugs |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 15 Sep 2007, Bernd Beuster wrote: > A simple test for the choosen random implementation: the run length > should be 2^31-2. The sequence of values which CCL::%NEXT-RANDOM-SEED computes should have that period. The behavior of RANDOM depends on how RANDOM uses those values. CCL::%NEXT-RANDOM-SEED should update a (MOD (1- (EXPT 2 31))) value to the next item in that sequence, but CCL::%NEXT-RANDOM-SEED only returns 16 of those 31 bits. To obtain 60 random bits (in the (RANDOM MOST-POSITIVE-FIXNUM) case), RANDOM has to call CCL::%NEXT-RANDOM-SEED at least 4 times (It actually does so 5 times). Depending on exactly how those 4 or 5 16-bit values are used to compute a 60-bit value, the period of (RANDOM MOST-POSITIVE-FIXNUM) may be more or less than the period of the 31-bit seed; in general, we should get about half as many 60-bit values before repetition as 31-bit values, since we have to update the 31-bit seed at least twice per 60-bit value. You were correct in noting that the seed wasn't being updated correctly and therefore led to a much shorter sequence than it should have. A fix for that should be in CVS within the next hour. I'd also agree that it's inefficient to be doing this 16 bits at at a time on a 64 bit machine; that'll change in the next release. > > > (defun random-run-length ( &optional (print t)) > "Should be 2^31-2)" > (declare (optimize speed)) > (loop with start fixnum = (random most-positive-fixnum) > for current fixnum = (random most-positive-fixnum) > for i fixnum from 1 > until (= current start) > finally (return i) > do (when (and print (zerop (mod i 10000000))) (print i)))) > > > ? (random-run-length nil) > 134217728 > ? (log * 2) > 27.0 > > Obviously not. > > > -- > Bernd > > > > > _______________________________________________ > Bug-openmcl mailing list > [email protected] > http://clozure.com/mailman/listinfo/bug-openmcl > >