Search code examples
testinghaskellrandomquickcheck

How to set constant seeds for Haskell's quickCheck function


Every time I run "quickCheck prop_xyz", a new random seed is used. How do I enforce QuickCheck to always use the same random seed?

Thanks!


Solution

  • The functionality you need is in Test.QuickCheck; use quickCheckWith to specify custom Args. In particular, there's the replay :: Maybe (StdGen, Int) field, which allows you to replay tests. So you can use the stdArgs defaults and tweak them; for instance,

    ghci> :load Main.hs
    ghci> import Test.QuickCheck
    ghci> import System.Random -- for mkStdGen
    ghci> quickCheckWith stdArgs{replay = Just (mkStdGen 42, 0)} prop_xyz
    

    The second component of the tuple has to do with the size of the test cases, but I forget exactly what.