Skip to content

Commit

Permalink
Merge remote-tracking branch 'phadej/splitmix-0.0.5-and-0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
nick8325 committed Jun 29, 2020
2 parents ef96526 + 5cd14f9 commit e2abb66
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion QuickCheck.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ library

-- Use splitmix on newer GHCs.
if impl(ghc >= 7.0)
Build-depends: splitmix >= 0.0.4
Build-depends: splitmix >= 0.0.5 && <0.2
else
cpp-options: -DNO_SPLITMIX

Expand Down
11 changes: 2 additions & 9 deletions src/Test/QuickCheck/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Data.List
import Data.Ord
import Data.Maybe
#ifndef NO_SPLITMIX
import System.Random.SplitMix(bitmaskWithRejection64', SMGen)
import System.Random.SplitMix(bitmaskWithRejection64', SMGen, nextInteger)
#endif
import Data.Word
import Data.Int
Expand Down Expand Up @@ -187,14 +187,7 @@ chooseInteger :: (Integer, Integer) -> Gen Integer
#ifdef NO_SPLITMIX
chooseInteger = choose
#else
chooseInteger (lo, hi)
| lo >= toInteger (minBound :: Int64) && lo <= toInteger (maxBound :: Int64) &&
hi >= toInteger (minBound :: Int64) && hi <= toInteger (maxBound :: Int64) =
fmap toInteger (chooseInt64 (fromInteger lo, fromInteger hi))
| lo >= toInteger (minBound :: Word64) && lo <= toInteger (maxBound :: Word64) &&
hi >= toInteger (minBound :: Word64) && hi <= toInteger (maxBound :: Word64) =
fmap toInteger (chooseWord64 (fromInteger lo, fromInteger hi))
| otherwise = choose (lo, hi)
chooseInteger (lo, hi) = MkGen $ \(QCGen g) _ -> fst (nextInteger lo hi g)

chooseWord64 :: (Word64, Word64) -> Gen Word64
chooseWord64 (lo, hi)
Expand Down
13 changes: 13 additions & 0 deletions src/Test/QuickCheck/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,26 @@ instance Read QCGen where
readsPrec n xs = [(QCGen g, ys) | (g, ys) <- readsPrec n xs]

instance RandomGen QCGen where
#ifdef NO_SPLITMIX
split (QCGen g) =
case split g of
(g1, g2) -> (QCGen g1, QCGen g2)

genRange (QCGen g) = genRange g
next (QCGen g) =
case next g of
(x, g') -> (x, QCGen g')
#else
split (QCGen g) =
case splitSMGen g of
(g1, g2) -> (QCGen g1, QCGen g2)

genRange (QCGen g) = (minBound, maxBound)

next (QCGen g) =
case nextInt g of
(x, g') -> (x, QCGen g')
#endif

newQCGen :: IO QCGen
#ifdef NO_SPLITMIX
Expand Down

0 comments on commit e2abb66

Please sign in to comment.