Add missing method genRange for StdGen (fixes #794)
authorsimonpj@microsoft <unknown>
Fri, 7 Jul 2006 15:19:01 +0000 (15:19 +0000)
committersimonpj@microsoft <unknown>
Fri, 7 Jul 2006 15:19:01 +0000 (15:19 +0000)
MERGE TO STABLE

Trac #794 reports (correctly) that the implementation of StdGen
only returns numbers in the range (0..something) rather than
(minBound, maxBound), which is what StdGen's genRange claims.

This commit fixes the problem, by implementing genRange for StdGen
(previously it just used the default method).

System/Random.hs

index f9762df..e1f39e8 100644 (file)
@@ -162,6 +162,7 @@ data StdGen
 instance RandomGen StdGen where
   next  = stdNext
   split = stdSplit
+  genRange _ = stdRange
 
 instance Show StdGen where
   showsPrec p (StdGen s1 s2) = 
@@ -342,7 +343,11 @@ intRange  = toInteger (maxBound::Int) - toInteger (minBound::Int)
 iLogBase :: Integer -> Integer -> Integer
 iLogBase b i = if i < b then 1 else 1 + iLogBase b (i `div` b)
 
+stdRange :: (Int,Int)
+stdRange = (0, 2147483562)
+
 stdNext :: StdGen -> (Int, StdGen)
+-- Returns values in the range stdRange
 stdNext (StdGen s1 s2) = (z', StdGen s1'' s2'')
        where   z'   = if z < 1 then z + 2147483562 else z
                z    = s1'' - s2''