More on Random
Jesse Welton
jwelton at pacific.mps.ohio-state.edu
Fri Jun 11 21:32:17 UTC 1999
David N. Smith \ wrote:
>
> Anyhow, how about this:
>
> seed := (Time millisecondClockValue bitAnd: 16r3FFFFFFF)
> bitXor: self hash + 1.
>
> The #bitAnd: assures that the clock value is less than the value 'm' and
> removes dependencies on the maximum clock value; it might change some day!
> The #bitXor: assures that the result is not zero, and the addition of 1
> assures against self hash answering zero. Most of this is paranoia, but
> then that's a disease old programmers get!
>
> Anyone see anything I missed?
Doesn't this initialize the seed to 0 if
(Time millisecondClockValue bitAnd: 16r3FFFFFFF) = (self hash + 1)?
That is, I think you need to bind the #bitXor: tighter than the #+, as
in:
seed := ((Time millisecondClockValue bitAnd: 16r3FFFFFFF)
bitXor: self hash) + 1.
Who said Smalltalk doesn't have operator precidence problems? :)
-Jesse
More information about the Squeak-dev
mailing list
|