When min - max range is close or equal to PHP_INT_MAX log() produces number of bits
equal to machine size integer. So $filter = (int) ((1 << $bits) - 1); evaluates to zero.
In this case getInteger(0, PHP_INT_MAX) returns only zeros.
$filter = (int) ((1 << $bits) - 1);
PR includes correct bit calculation and test
fix Rand::getInteger() range overflow issue
test for Rand::getInteger() range overflow issue
use static::getBytes instead of self::getBytes
If you want to be sure (high probability) that Rand::getInteger does not give only zero values you should increase the number of cycles, for instance from 5 to 100.
Why are you using the XOR operator here? The sum (+=) is not a better choice here?
Actually the purpose of the test was also to ensure that getInteger() does not return same value (not just zero) on every call. There is a chance that total sum of values would be 0 so += could produce false positives, but you're right ^= doesn't work either. I will come up with better test.
use static:: ; improved test
@samsonasik @ezimuel PTAL
Is it normal $values to be negative?
I've changed the test for assert $values to be greater than 0
Failed asserting that -5.1650883406387E+20 is greater than 0.
Ok, I see what is happenning. $values probably has a value which produce a int overflow as result of operate with big numbers.