RandomDataGenerator implements RandomData, Serializable { public double nextUniform(double lower, double upper) throws NumberIsTooLargeException, NotFiniteNumberException, NotANumberException { return nextUniform(lower, upper, false); } 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 testNextUniformExtremeValues() { double x = randomData.nextUniform(-Double.MAX_VALUE, Double.MAX_VALUE); double y = randomData.nextUniform(-Double.MAX_VALUE, Double.MAX_VALUE); Assert.assertFalse(x == y); Assert.assertFalse(Double.isNaN(x)); Assert.assertFalse(Double.isNaN(y)); Assert.assertFalse(Double.isInfinite(x)); Assert.assertFalse(Double.isInfinite(y)); }
@Test public void testNextPoissonConsistency() { for (int i = 1; i < 100; i++) { checkNextPoissonConsistency(i); } for (int i = 1; i < 10; i++) { checkNextPoissonConsistency(randomData.nextUniform(1, 1000)); } for (int i = 1; i < 10; i++) { checkNextPoissonConsistency(randomData.nextUniform(1000, 10000)); } }
@Test public void testNextUniformIAE() { try { randomData.nextUniform(4, 3); Assert.fail("MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } try { randomData.nextUniform(0, Double.POSITIVE_INFINITY); Assert.fail("MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } try { randomData.nextUniform(Double.NEGATIVE_INFINITY, 0); Assert.fail("MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } try { randomData.nextUniform(0, Double.NaN); Assert.fail("MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } try { randomData.nextUniform(Double.NaN, 0); Assert.fail("MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } }
@Test public void testNextUniformExclusiveEndpoints() { for (int i = 0; i < 1000; i++) { double u = randomData.nextUniform(0.99, 1); Assert.assertTrue(u > 0.99 && u < 1); } }
@Test public void testNextInversionDeviate() { RandomGenerator rg = new Well19937c(100); RandomDataGenerator rdg = new RandomDataGenerator(rg); double[] quantiles = new double[10]; for (int i = 0; i < 10; i++) { quantiles[i] = rdg.nextUniform(0, 1); } rg.setSeed(100); BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY); for (int i = 0; i < 10; i++) { double value = betaDistribution.sample(); Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9); } }