[squeak-dev] Bad value for Random seed ?

Frank Shearar frank.shearar at gmail.com
Sun Sep 21 15:01:05 UTC 2014


On 21 September 2014 14:04, Stéphane Rollandin <lecteur at zogotounga.net> wrote:
> Hello,
>
>  (Random seed: 16457315536128) nextInt: 11
>
> gives -1853
>
>
> Am I missing something ?

It looks like you're violating one of the (unwritten) assumptions of
the class. The class comment says "It is an adaptation of the
Park-Miller RNG which uses Floats to avoid the need for LargeInteger
arithmetic." Also, #nextValue says in its comment "This method
generates random instances of Integer in the interval 0 to
16r7FFFFFFF. " So with that in mind, we can see why you'd get a
negative number - integer overflow.

But having said that, I don't know if it's reasonable to assume that
the reader's dug into the guts of Random, especially when #nextint:
says "Answer a random integer in the interval [1, anInteger]." We
usually take pains to automatically convert between bignum and small
integers, and here we don't. What if you _do_ want a random number
that might be larger than 2^32?

frank

> Stef


More information about the Squeak-dev mailing list