From 1f6ed5711c4a8697564e42a832522c925442aa6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Sat, 4 Jan 2020 10:58:22 +0100 Subject: [PATCH] Warn about non-uniform distribution with QuickCheck --- Crypto/Random.hs | 4 ++++ tests/Utils.hs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Crypto/Random.hs b/Crypto/Random.hs index 37d4124..4cea74b 100644 --- a/Crypto/Random.hs +++ b/Crypto/Random.hs @@ -80,6 +80,10 @@ drgNewSeed (Seed seed) = initialize seed -- -- It can also be used in other contexts provided the input -- has been properly randomly generated. +-- +-- Note that the @Arbitrary@ instance provided by QuickCheck for 'Word64' does +-- not have a uniform distribution. It is often better to use instead +-- @arbitraryBoundedRandom@. drgNewTest :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG drgNewTest = initializeWords diff --git a/tests/Utils.hs b/tests/Utils.hs index 03ba521..bf16bb4 100644 --- a/tests/Utils.hs +++ b/tests/Utils.hs @@ -19,7 +19,7 @@ newtype TestDRG = TestDRG (Word64, Word64, Word64, Word64, Word64) deriving (Show,Eq) instance Arbitrary TestDRG where - arbitrary = TestDRG `fmap` arbitrary + arbitrary = TestDRG `fmap` arbitrary -- distribution not uniform withTestDRG (TestDRG l) f = fst $ withDRG (drgNewTest l) f