Skip to content

Add Choose[BigInt] #631

Closed
Closed
@dmurvihill

Description

@dmurvihill

ScalaCheck's arbitrary BigInt is bounded, which can be very limiting for some applications and requires e.g. scientific and cryptographic users to implement custom generators. Providing a Choose[BigInt] implementation could save considerable boilerplate. This is my implementation:

  implicit object chooseBigInt extends Gen.Choose[BigInt] {
    @tailrec
    def choose(min: BigInt, max: BigInt): Gen[BigInt] = {
      val n = min + BigInt((max - min).bitLength, Random)
      if (n > max) choose(min, max) else n
    }
  }

Any interest in a PR?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions