[Haskell-cafe] A Random Question
haskell at zeuxis.de
Sat Dec 15 11:51:07 EST 2007
Dominic Steinitz schrieb:
>> What do you need, i.e., what meaning do you attribute to the words
>> "predictable" and "arbitrary"?
> Apologies - I didn't explain my problem clearly.
> I want to say something like:
> instance Arbitrary Foo where
> arbitrary = choose (Foo 1, Foo 5)
> but the "random" values are generated by my own random number generator
> not the standard one.
> Does that make sense? The reason I'm trying to do this is I am
> generating random test data but some of it needs to be predictable.
When I work with QuickCheck, it often finds some interesting corner
cases. I prefer to solve this one problem before further testing, so I
use a little wrapper around QuickCheck to be able to reproduce a
import Test.QuickCheck hiding (test)
import qualified Test.QuickCheck as QC (test)
test prop =
do getStdGen >>= print
-- for repeatable tests
testRnd prop r1 r2 =
do setStdGen . read $ show r1 ++ " " ++ show r2
'test' simply dumps the current generator (show as two numbers) and one
can use these two numbers with 'testRnd' to repeat the test with exactly
the same data.
Perhaps this technique is useful for your problem.
More information about the Haskell-Cafe