[squeak-dev] Random randomness

Andreas Raab andreas.raab at gmx.de
Fri Aug 22 05:34:14 UTC 2008


Hi -

Today I've encountered two very interesting issues with respect to 
Random. First, there seems to be a bug when using very large seeds, for 
example:

   rnd := Random seed: 300000000000.
   rnd nextInt: 100.

This answers -121 which is just plain completely wrong! Any ideas for 
how to fix this?

Secondly, what is a good way to seed a random number generator that one 
will only pull out very few numbers? We found that a naive approach 
works very badly which is illustrated here:

   1 to: 100 do:[:i|
     rnd := Random new.
     Transcript show: (rnd nextInt: 100); space.
   ].

There is almost no variation in the numbers. If this would be running 
out of one image, I would do something like here:

   base := Random new.
   1 to: 100 do:[:i|
     rnd := Random seed: (base nextInt: 1234567).
     Transcript show: (rnd nextInt: 100); space.
   ].

which looks much more nicely distributed but unfortunately this code 
will be run in different images. So having something that is based on 
the millsecond clock is probably good but there still seems to be very 
little variation when I run a couple of tests.

Any insights welcome!

Cheers,
   - Andreas



More information about the Squeak-dev mailing list