AbstractIntegerDistribution implements IntegerDistribution, Serializable { public int inverseCumulativeProbability(final double p) throws OutOfRangeException { if (p < 0.0 || p > 1.0) { throw new OutOfRangeException(p, 0, 1); } int lower = getSupportLowerBound(); if (p == 0.0) { return lower; } if (lower == Integer.MIN_VALUE) { if (checkedCumulativeProbability(lower) >= p) { return lower; } } else { lower -= 1; } int upper = getSupportUpperBound(); if (p == 1.0) { return upper; } final double mu = getNumericalMean(); final double sigma = FastMath.sqrt(getNumericalVariance()); final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0); if (chebyshevApplies) { double k = FastMath.sqrt((1.0 - p) / p); double tmp = mu - k * sigma; if (tmp > lower) { lower = ((int) FastMath.ceil(tmp)) - 1; } k = 1.0 / k; tmp = mu + k * sigma; if (tmp < upper) { upper = ((int) FastMath.ceil(tmp)) - 1; } } return solveInverseCumulativeProbability(p, lower, upper); } @Deprecated protected  AbstractIntegerDistribution(); protected  AbstractIntegerDistribution(RandomGenerator rng); double cumulativeProbability(int x0, int x1); int inverseCumulativeProbability(final double p); void reseedRandomGenerator(long seed); int sample(); int[] sample(int sampleSize); double logProbability(int x);  }
@Test public void testInverseCumulativeProbabilityMethod() { double precision = 0.000000000000001; Assert.assertEquals(1, diceDistribution.inverseCumulativeProbability(0)); Assert.assertEquals(1, diceDistribution.inverseCumulativeProbability((1d-Double.MIN_VALUE)/6d)); Assert.assertEquals(2, diceDistribution.inverseCumulativeProbability((1d+precision)/6d)); Assert.assertEquals(2, diceDistribution.inverseCumulativeProbability((2d-Double.MIN_VALUE)/6d)); Assert.assertEquals(3, diceDistribution.inverseCumulativeProbability((2d+precision)/6d)); Assert.assertEquals(3, diceDistribution.inverseCumulativeProbability((3d-Double.MIN_VALUE)/6d)); Assert.assertEquals(4, diceDistribution.inverseCumulativeProbability((3d+precision)/6d)); Assert.assertEquals(4, diceDistribution.inverseCumulativeProbability((4d-Double.MIN_VALUE)/6d)); Assert.assertEquals(5, diceDistribution.inverseCumulativeProbability((4d+precision)/6d)); Assert.assertEquals(5, diceDistribution.inverseCumulativeProbability((5d-precision)/6d)); Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((5d+precision)/6d)); Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((6d-precision)/6d)); Assert.assertEquals(6, diceDistribution.inverseCumulativeProbability((6d)/6d)); }