I need to generate a random list of numbers of a given size whose total is less than a given fixed threshold using ScalaCheck. In other words, do something like:
val threshold = 3000
val listGenerator = Gen.listOfN(2000, Gen.choose(1,2000)) suchThat { _.sum < theshold }
While the above expresses exactly what I want to achieve, it doesn't work as the suchThat clause ends up discarding the vast majority of generated values.