Search code examples
scalascalacheck

How do you generate a shuffled sequence with ScalaCheck?


I've been trying to generate shuffled sequences with scalacheck. Scalacheck doesn't provide any generator to do it straightforwardly, and I couldn't find any easy answer online. After a bit of thinking, below is how I did it. I hope others will find if useful.


Solution

  • org.scalacheck.Gen.pick(n: Int, l: Iterable[T]): Gen[Seq[T]] picks n distinct elements from l in random order. Call pick with n = l.length, and you will generate a randomly