Fix randomIvalDouble so that it will not produce values more than a few ULPs below...
authorJames Cook <james.cook@usma.edu>
Mon, 12 Apr 2010 13:26:38 +0000 (13:26 +0000)
committerJames Cook <james.cook@usma.edu>
Mon, 12 Apr 2010 13:26:38 +0000 (13:26 +0000)
System/Random.hs

index f64d4dd..ce7f856 100644 (file)
@@ -340,13 +340,13 @@ randomIvalDouble (l,h) fromDouble rng
            let
             scaled_x = 
                fromDouble ((l+h)/2) + 
-                fromDouble ((h-l) / realToFrac int32Range) *
+                fromDouble ((h-l) / realToFrac int32Count) *
                fromIntegral (x::Int32)
            in
            (scaled_x, rng')
 
-int32Range :: Integer
-int32Range = toInteger (maxBound::Int32) - toInteger (minBound::Int32)
+int32Count :: Integer
+int32Count = toInteger (maxBound::Int32) - toInteger (minBound::Int32) + 1
 
 iLogBase :: Integer -> Integer -> Integer
 iLogBase b i = if i < b then 1 else 1 + iLogBase b (i `div` b)