New Random Number Generator

Tim Rowledge tim at sumeru.stanford.edu
Sun Jul 28 05:07:44 UTC 2002


The only oddnes I can see right now (hey, it's late and I'm no random
number expert) is that the C code is using unsigned which means the >>
shifts will lose sign bit info. Smalltalk will keep it, thus giving you
different bit patterns.  Consider, in both languages,
	-1 >> 4
In Squeak it is -1. I C, with -1 being the value of an unsinged int type
(yuck, how I hate that) it will be 268435455.

I think you should get better answers (though slower, sadly) ifyou
change your right shifting 'macros' to also #bitAnd: with a suitable
value to get rid of the extended sign bits. Um ,for temperingShiftU:, I
think something like
	^(anInteger bitAnd: 2r111111111111111111111 "32 -11 = 21 1's")
should do it. Actually since you no longer need the bitAnd: 16rFFFFFFFF
it will take the same time.

Try the same wherever you have a right shift.

tim

-- 
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
If it was easy, the hardware people would take care of it.




More information about the Squeak-dev mailing list