I'm trying to right a good number generator that covers
def uInt64s : Gen[BigInt] = Gen.choose(0,64).map(pow2(_) - 1)
2^n - 1
0 <= n < 2^64
Okay, maybe I am missing something here, but isn't it as simple as this?
def uInt64s : Gen[BigInt] = Gen.chooseNum(Long.MinValue,Long.MaxValue) .map(x => BigInt(x) + BigInt(2).pow(63))
Longs already have the correct number of bits - just adding 2^63 so
Long.MinValue becomes 0 and
Long.MaxValue becomes 2^64 - 1. And doing the addition with
BigInts of course.
I was curious about the distribution of generated values. Apparently the distribution of
chooseNum is not uniform, since it prefers special values, but the edge cases for Longs are probably also interesting for UInt64s:
/** Generates numbers within the given inclusive range, with * extra weight on zero, +/- unity, both extremities, and any special * numbers provided. The special numbers must lie within the given range, * otherwise they won't be included. */ def chooseNum[T](minT: T, maxT: T, specials: T*)(