[Haskell] trouble with the random number generator

Ian Lynagh igloo at earth.li
Thu Apr 8 12:18:25 EDT 2010


On Thu, Apr 08, 2010 at 10:20:25AM -0400, Garrett Mitchener wrote:
> 
> 1/2 - 2^31/(2^32-1)  = 2^31( 1/2^32 - 1/(2^32-1) ) = -1.164e-10 < 0
> 
> which is outside the required range.

Yup, looks like a bug to me.

Even if it were fixed so that the maths seemed to show no bug, I
wouldn't be surprised if you could get an out-of-range result due to
Doubles not being able to represent all values exactly.

I'd suggest you make a library submission to fix it, so that people can
sanity check the new code:
    http://www.haskell.org/haskellwiki/Library_submissions


Thanks
Ian



More information about the Haskell mailing list