[squeak-dev] The Squeak Random Number Generator

Andres Valloud AVALLOUD at roadrunner.com
Tue Sep 9 01:08:45 UTC 2008


Without looking at the implementation in Squeak, the Park Miller 
generator in VisualWorks looks exactly the same and it may not be a good 
idea to return a double from it.  This is because Park Miller produces 
(IIRC) 31 random bits, and the double mantissas have 53 bits (including 
the implicit bit), so the behavior of up to 22 bits is undefined.

In the case of VisualWorks, bit #32 was always 1 due to the arithmetic 
operations used.  Note this is not an issue with Park Miller, but rather 
with attempting to answer results more precise than possible.  Other 
bits had questionable behavior too.  Lagged fibonacci generators are 
both better and faster.

Andres.


John M McIntosh wrote:
> At the time when David N Smith provided it, it replaced a very flawed 
> implementation.
>
> From the comments you can see it's a:
> "This Random Number Generator graciously contributed by David N. 
> Smith.  It is an adaptation of the Park-Miller RNG which uses Floats 
> to avoid the need for LargeInteger arithmetic.:
>
> Normally it would return integers, but as you see it returns floats, 
> to avoid the creation and time needed to deal with large integer objects.
>
> The theItsCompletelyBrokenTest method returns values that don't match 
> for some of the entries due to rounding. Someone with a powerpc 
> machine would need
> to cross check using an older VM. We altered the current VMs a few 
> years back to align floating point rounding rules when it was 
> discovered they gave different results on the
> platforms for Croquet.
>
>
> On Sep 7, 2008, at 4:45 AM, Jim Rosenberg wrote:
>
>> I'm getting very queasy feelings about Random.
>>
>> My understanding of the linear congruence random number generator 
>> algorithm is that it depends (crucially) on doing exact integer 
>> arithmetic with enough precision to hold all the digits in the 
>> multiplication at its heart. Using floating point arithmetic for a 
>> linear congruence algorithm is one of the classic ways of 
>> implementing a random number generator that is badly flawed.
>>
>> In my version of Squeak (3.8) the class Random seems to be using 
>> floats. Uh oh.
>>
>> Can somebody comment? Has the Squeak random number generator ever 
>> been tested? (Knuth gives a whole raft of tests ...)
>>
>
> -- 
> =========================================================================== 
>
> John M. McIntosh <johnmci at smalltalkconsulting.com>
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> =========================================================================== 
>
>
>
>
>




More information about the Squeak-dev mailing list