testlib
testlib copied to clipboard
rnd.next(0ULL, -1ULL) overflow crashes
to = 2^64-1, from = 0, therefore to - from + 1 = 2^64 = 0 for unsigned long long.
Is there any solutions to random in [0, 2^64-1] in one shot?
By taking a look at testlib.h, unsigned long long next(unsigned long long n)
is using long long next(long long n)
, so basically you can't reach 2^64-1.
To create your rnd.next for unsigned 64bits you can just modify nextBits to operate with unsigned long long all the way instead of long long (seed
, multiplier
, addend
and mask
are all unsigned long long
so it's not a problem) and accept 64bits... I don't know why they add this limitation