We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider the following test:
@Example void integers() { IntegerArbitrary integers = Arbitraries.integers().withDistribution(RandomDistribution.uniform()); integers.sampleStream().limit(50).forEach(System.out::println); }
Which will only create three different values:
-2147483647 -2147483648 1
The problem is the implementation of SmallUniformGenerator:
class SmallUniformNumericGenerator implements RandomDistribution.RandomNumericGenerator { private final int min; private final int max; SmallUniformNumericGenerator(BigInteger min, BigInteger max) { this.min = min.intValueExact(); this.max = max.intValueExact(); } @Override public BigInteger next(Random random) { int bound = Math.abs(max - min) + 1; int value = random.nextInt(bound >= 0 ? bound : Integer.MAX_VALUE) + min; return BigInteger.valueOf(value); } }
which should only be used if max-min < Integer.MAX_VALUE. See:
max-min < Integer.MAX_VALUE
public class UniformRandomDistribution implements RandomDistribution { @Override public RandomNumericGenerator createGenerator( int genSize, BigInteger min, BigInteger max, BigInteger center ) { // Small number generation can be faster if (isWithinIntegerRange(min, max)) { return new SmallUniformNumericGenerator(min, max); } else { return new BigUniformNumericGenerator(min, max); } } private static boolean isWithinIntegerRange(BigInteger min, BigInteger max) { return min.compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) >= 0 && max.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) <= 0; } }
The text was updated successfully, but these errors were encountered:
Fixed bug #544
0313063
Fixed in 0313063
Sorry, something went wrong.
Released in 1.8.3-SNAPSHOT
1.8.3-SNAPSHOT
No branches or pull requests
Testing Problem
Consider the following test:
Which will only create three different values:
Discussion
The problem is the implementation of SmallUniformGenerator:
which should only be used if
max-min < Integer.MAX_VALUE
. See:The text was updated successfully, but these errors were encountered: