New Random Number Generator

Tim Rowledge tim at sumeru.stanford.edu
Thu Aug 1 00:25:51 UTC 2002


Mark4Flies at aol.com is claimed by the authorities to have written:

> << OK, I have a working trivial plugin for this that just does a 30bit int 
> for now. >>
> 
> I do not understand what is different about working with 30 bit integers as 
> opposed to the 32 bit version I started with?
It's a detail Smalltalk thing - SmallIntegers are 30bits with 1 sign bit
(plus the hidden tag bit) and so restricting the values generated to
30bits guarantees a simple life and still gives a billion or so
+ve values. Since the C code has a 31bit routine that uses the 32bit and
merely shifts right one, I assume that shifting right 2 will be ok. I
could be wrong; it has happened before.
> 
> << Seems to work ok - making a bag of 1000 values suggests it at least does a 
> tolerable job. Though it does bother me a bit that in a whole load of tests 
> I've not seen any number with less than a half-dozen digits. I'll let you 
> numerics fanatics worry about that part. >>
> 
> You mean that all of the sample numbers have at least six decimal digits?
Yup. As Ian P pointed out yesterday, one would expect only one in
1000 numbers to be less than a million when using 30bit values. I did a
much larger test and it looks reasonable to my eyes. It ought to be run
through some tester or other.
> 
> << So what sorts of values would be useful? Is just a 30bit int ok with any 
> further cleverness being done in the image? >>
> 
> I am not sure if the desirable properties of the Mersenne Twister are 
> preserved if we drop down from 32 bit words. I was hoping to duplicate the 
> algorithm exactly. (Note I said "I", not "you" !) For casual use, it may not 
> be any better or worse than the current generator. For serious use, though, 
> it should reproduce the C program. If it does not, then one suspects that 
> other properties are lost, too.
One of the little joys of using a vm plugin for replicating C code like
this (with all those bit twiddles) is that you simply steal the C and
use it :-) Whihc neatly sidesteps the problems you've been having....

tim
-- 
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Strange OpCodes: FCE: Fill Core with Epoxy




More information about the Squeak-dev mailing list