@Test void nextBigDecimal_withNegativeSameScale_works() { BigDecimal lower = new BigDecimal("0.1"); BigDecimal upper = new BigDecimal("0.4"); Set<BigDecimal> expected = SetUtils.setOf(lower, new BigDecimal("0.2"), new BigDecimal("0.3")); assertTrue(Stream.generate(() -> random.nextBigDecimal(lower, upper)) .limit(10) .allMatch(expected::contains)); }
@Override public BigDecimal nextBigDecimal(BigDecimal lowerInclusive, BigDecimal upperExclusive) { int lowerScale = lowerInclusive.scale(); int upperScale = upperExclusive.scale(); int greatestScale = Math.max(lowerScale, upperScale); BigInteger lowerValue = adjustToScale(lowerInclusive, greatestScale); BigInteger upperValue = adjustToScale(upperExclusive, greatestScale); return new BigDecimal(nextBigInteger(lowerValue, upperValue), greatestScale); }
JavaUtilRandomNumberGenerator implements RandomNumberGenerator { @Override public BigDecimal nextBigDecimal(BigDecimal lowerInclusive, BigDecimal upperExclusive) { int lowerScale = lowerInclusive.scale(); int upperScale = upperExclusive.scale(); int greatestScale = Math.max(lowerScale, upperScale); BigInteger lowerValue = adjustToScale(lowerInclusive, greatestScale); BigInteger upperValue = adjustToScale(upperExclusive, greatestScale); return new BigDecimal(nextBigInteger(lowerValue, upperValue), greatestScale); } }
JavaUtilRandomNumberGenerator implements RandomNumberGenerator { @Override public BigDecimal nextBigDecimal(BigDecimal lowerInclusive, BigDecimal upperExclusive) { int lowerScale = lowerInclusive.scale(); int upperScale = upperExclusive.scale(); int greatestScale = Math.max(lowerScale, upperScale); BigInteger lowerValue = adjustToScale(lowerInclusive, greatestScale); BigInteger upperValue = adjustToScale(upperExclusive, greatestScale); return new BigDecimal(nextBigInteger(lowerValue, upperValue), greatestScale); } JavaUtilRandomNumberGenerator();  JavaUtilRandomNumberGenerator(long seed); }
JavaUtilRandomNumberGenerator implements RandomNumberGenerator { @Override public BigDecimal nextBigDecimal(BigDecimal lowerInclusive, BigDecimal upperExclusive) { int lowerScale = lowerInclusive.scale(); int upperScale = upperExclusive.scale(); int greatestScale = Math.max(lowerScale, upperScale); BigInteger lowerValue = adjustToScale(lowerInclusive, greatestScale); BigInteger upperValue = adjustToScale(upperExclusive, greatestScale); return new BigDecimal(nextBigInteger(lowerValue, upperValue), greatestScale); } JavaUtilRandomNumberGenerator();  JavaUtilRandomNumberGenerator(long seed); @Override int nextInt(); @Override int nextInt(int bound); @Override long nextLong(long lowerInclusive, long upperExclusive); @Override double nextDouble(double lowerInclusive, double upperExclusive); @Override BigDecimal nextBigDecimal(BigDecimal lowerInclusive, BigDecimal upperExclusive); }
JavaUtilRandomNumberGenerator implements RandomNumberGenerator { @Override public BigDecimal nextBigDecimal(BigDecimal lowerInclusive, BigDecimal upperExclusive) { int lowerScale = lowerInclusive.scale(); int upperScale = upperExclusive.scale(); int greatestScale = Math.max(lowerScale, upperScale); BigInteger lowerValue = adjustToScale(lowerInclusive, greatestScale); BigInteger upperValue = adjustToScale(upperExclusive, greatestScale); return new BigDecimal(nextBigInteger(lowerValue, upperValue), greatestScale); } JavaUtilRandomNumberGenerator();  JavaUtilRandomNumberGenerator(long seed); @Override int nextInt(); @Override int nextInt(int bound); @Override long nextLong(long lowerInclusive, long upperExclusive); @Override double nextDouble(double lowerInclusive, double upperExclusive); @Override BigDecimal nextBigDecimal(BigDecimal lowerInclusive, BigDecimal upperExclusive);  }