[Haskell-cafe] quickCheck problem

Richard A. O'Keefe ok at cs.otago.ac.nz
Wed Oct 7 23:16:29 UTC 2015

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.

More information about the Haskell-Cafe mailing list