From 7d423cd34e29881e09b5bc3aa6b1eb8ca8346a46 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft" Date: Fri, 7 Jul 2006 15:19:01 +0000 Subject: [PATCH] Add missing method genRange for StdGen (fixes #794) 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/System/Random.hs b/System/Random.hs index f9762df..e1f39e8 100644 --- a/System/Random.hs +++ b/System/Random.hs @@ -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'' -- 1.7.10.4