[Haskell-cafe] quickCheck problem
Roelof Wobben
r.wobben at home.nl
Thu Oct 8 05:03:48 UTC 2015
Op 8-10-2015 om 01:16 schreef Richard A. O'Keefe:
> You can generate two unequal integers by doing
>
> prop_twoDifferent :: Int -> Int -> Bool
> prop_twoDifferent x y = yourFn2 x y'
> where y' = if y >= x then y+1 else y
>
> Letting the number of distinct Int values be N,
> there are N*N pairs of Ints but only N*(N-1) pairs of
> *different* Ints, so this technique will generate some
> x y' pairs more often than others. In fact you will
> get (x,minBound::Int) with probability 2/N and
> (x,y>minBound) with probability 1/N.
> The advantage of using a guard is that the probabilities
> come out right (it's the "rejection method", in
> statistical parlance).
>
> You can use that method to generate
> x x y
> x y x
> y x x
>
> You can iterate the same idea to generate triples.
>
>
>
> -----
> Geen virus gevonden in dit bericht.
> Gecontroleerd door AVG - www.avg.com
> Versie: 2015.0.6140 / Virusdatabase: 4435/10775 - datum van uitgifte: 10/07/15
>
>
Thanks all.
Enough to study and try.
Roelof
More information about the Haskell-Cafe
mailing list