RandomDataGenerator implements RandomData, Serializable { public int nextInt(final int lower, final int upper) throws NumberIsTooLargeException { return new UniformIntegerDistribution(getRandomGenerator(), lower, upper).sample(); } RandomDataGenerator();  RandomDataGenerator(RandomGenerator rand); String nextHexString(int len); int nextInt(final int lower, final int upper); long nextLong(final long lower, final long upper); String nextSecureHexString(int len); int nextSecureInt(final int lower, final int upper); long nextSecureLong(final long lower, final long upper); long nextPoisson(double mean); double nextGaussian(double mu, double sigma); double nextExponential(double mean); double nextGamma(double shape, double scale); int nextHypergeometric(int populationSize, int numberOfSuccesses, int sampleSize); int nextPascal(int r, double p); double nextT(double df); double nextWeibull(double shape, double scale); int nextZipf(int numberOfElements, double exponent); double nextBeta(double alpha, double beta); int nextBinomial(int numberOfTrials, double probabilityOfSuccess); double nextCauchy(double median, double scale); double nextChiSquare(double df); double nextF(double numeratorDf, double denominatorDf); double nextUniform(double lower, double upper); double nextUniform(double lower, double upper, boolean lowerInclusive); int[] nextPermutation(int n, int k); Object[] nextSample(Collection<?> c, int k); void reSeed(long seed); void reSeedSecure(); void reSeedSecure(long seed); void reSeed(); void setSecureAlgorithm(String algorithm, String provider); RandomGenerator getRandomGenerator();  }
@Test public void testNextIntExtremeValues() { int x = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); int y = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); Assert.assertFalse(x == y); }
@Test public void testNextIntIAE() { try { randomData.nextInt(4, 3); Assert.fail("MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } }
@Test public void testNextIntWideRange() { int lower = -0x6543210F; int upper = 0x456789AB; int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for (int i = 0; i < 1000000; ++i) { int r = randomData.nextInt(lower, upper); max = FastMath.max(max, r); min = FastMath.min(min, r); Assert.assertTrue(r >= lower); Assert.assertTrue(r <= upper); } double ratio = (((double) max) - ((double) min)) / (((double) upper) - ((double) lower)); Assert.assertTrue(ratio > 0.99999); }