More on Random

John.Maloney at disney.com John.Maloney at disney.com
Fri Jun 11 16:33:02 UTC 1999


At 3:43 PM -0400 6/10/99, Bob Arning wrote:
>>I think Dan added the multiply by self hash; I'm not sure why. Anyone have
>>any ideas?
>
>My guess would be so that two Randoms instantiated within the same millisecond would have different seeds (or, at least, probably would). So, a better idea might be:
>
>	" Set a reasonable Park-Miller starting seed "
>	seed := Time millisecondClockValue bitXor: self hash.
>
>or, to be incredibly safe (since a seed of zero is also a disaster):
>
>	seed := (Time millisecondClockValue bitXor: self hash) max: 1.

Bob is exactly right. I added the multiply by self hash so that
generators instantiated within the same clock tick would start with
different hash values. (Actually, I started by *adding* self hash,
which would have been safe, given the range limit of millisecondClockValue.
I should have stuck with that!)

Many thanks to Juan for noticing the bug and for you and David Smith
for analyzing it. David, is one of the proposals above the best fix
or would you propose something else? Should it do a "self next" at
the end of the initialization?

	-- John





More information about the Squeak-dev mailing list