A not so Random Random
Jesse Welton
jwelton at pacific.mps.ohiostate.edu
Wed May 26 13:56:08 UTC 1999
Juan Cires Martinez wrote:
>
> I am using a lot of Randoms lately, and something strange has happened a
> couple of times today: I get Randoms which after a while produce an
> unending sequence of 1.0s. The instance variables of these Randoms are:
>
> seed: 2.147483647e9
> a: 16807.0
> m: 2.147483647e9
> q: 127773.0
> r: 2836.0
>
> It is quite annoying. I do not know the details of the random number
> generation algorithm. Is there a way to avoid it besides explicit
> testing for 1.0 in Random>>next?
Most random number generators perform their internal computations on
integers only. Squeak's RNG algorithm certainly appears to be based
on such a system... so can anyone explain why the calculations are all
being done in floating point? I would expect this to cause trouble
with roundoff. (The integerbased origins of the algorithm can be
glimpsed at least in the seed initialization, Random>>seed: anInteger.
So what's going on here, exactly?)
It seems to me the correct solution is to take out all the asFloat
stuff, and apply it instead to the return value of Random>>next. That
way, all calculations are performed internally with integers, which
shouldn't cause the problem described above, and would be more
amenable to producing various random integer distributions.
Um, does that mean I'm elected?
Jesse Welton
More information about the Squeakdev
mailing list
