### Question:
ZipfDistribution extends AbstractDiscreteDistribution { @Override public DiscreteDistribution.Sampler createSampler(final UniformRandomProvider rng) { return new RejectionInversionZipfSampler(rng, numberOfElements, exponent)::sample; } ZipfDistribution(int numberOfElements,
                            double exponent); int getNumberOfElements(); double getExponent(); @Override double probability(final int x); @Override double logProbability(int x); @Override double cumulativeProbability(final int x); @Override double getMean(); @Override double getVariance(); @Override int getSupportLowerBound(); @Override int getSupportUpperBound(); @Override boolean isSupportConnected(); @Override DiscreteDistribution.Sampler createSampler(final UniformRandomProvider rng);  }### Answer:
@Test void testSamplingExtended() { final int sampleSize = 1000; final int[] numPointsValues = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100 }; final double[] exponentValues = { 1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 2e-1, 5e-1, 1. - 1e-9, 1.0, 1. + 1e-9, 1.1, 1.2, 1.3, 1.5, 1.6, 1.7, 1.8, 2.0, 2.5, 3.0, 4., 5., 6., 7., 8., 9., 10., 20., 30., 100., 150. }; for (final int numPoints : numPointsValues) { for (final double exponent : exponentValues) { double weightSum = 0.; final double[] weights = new double[numPoints]; for (int i = numPoints; i >= 1; i -= 1) { weights[i - 1] = Math.pow(i, -exponent); weightSum += weights[i - 1]; } final DiscreteDistribution.Sampler distribution = new ZipfDistribution(numPoints, exponent).createSampler( RandomSource.create(RandomSource.WELL_19937_C, 6)); final double[] expectedCounts = new double[numPoints]; final long[] observedCounts = new long[numPoints]; for (int i = 0; i < numPoints; i++) { expectedCounts[i] = sampleSize * (weights[i] / weightSum); } final int[] sample = AbstractDiscreteDistribution.sample(sampleSize, distribution); for (final int s : sample) { observedCounts[s - 1]++; } TestUtils.assertChiSquareAccept(expectedCounts, observedCounts, 0.001); } } }