scalascalacheck

How to generate increasing sequence in ScalaCheck?


I'm trying to generate sequence of increasing numbers using ScalaCheck.

I would like to achieve something like this:

0 2 4 6

Which was achieved by increasing range 0..3 by step of 2:

0 * 2 = 0
1 * 2 = 2
2 * 2 = 4
3 * 2 = 6

Thanks for help. Sorry if question has been questioned before.


Solution

  • Well it appears not so difficult to generate random sequence. Sorry I needed to be more specific about predictability.

    object GenerateSequence {
    
      def apply(maxSize: Int, maxStep: Int): Gen[Seq[Int]] = {
        for {
          size <- Gen.chooseNum(1, maxSize)
          step <- Gen.chooseNum(1, maxStep)
        } yield {
          (0 to size).map(_ * step)
        }
      }
    }