[Haskell-cafe] Bug with QuickCheck 1.1 and GHC 6.8.2
Johan Tibell
johan.tibell at gmail.com
Thu Aug 14 05:17:33 EDT 2008
On Thu, Aug 14, 2008 at 1:58 AM, Patrick Perry <patperry at stanford.edu> wrote:
> variant :: Int -> Gen a -> Gen a
> variant v (Gen m) = Gen (\n r -> m n (rands r !! v'))
> where
> v' = abs (v+1) `mod` 10000
> rands r0 = r1 : rands r2 where (r1, r2) = split r0
Note that if you have a uniformly distributed random value in [0, n)
and take its value mod k you don't end up with another random
uniformly distributed value unless n `mod` k == 0. Consider n = 3 and
k = 2. What you can do is to throw away all random numbers larger than
n - (n `mod` k) and just generate a new number. This will terminate
with a high probability if n >> k.
Cheers,
Johan
More information about the Haskell-Cafe
mailing list