RandomDataGenerator implements RandomData, Serializable { public long nextPoisson(double mean) throws NotStrictlyPositiveException { return new PoissonDistribution(getRandomGenerator(), mean, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS).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 testNextPoisson() { try { randomData.nextPoisson(0); Assert.fail("zero mean -- expecting MathIllegalArgumentException"); } catch (MathIllegalArgumentException ex) { } try { randomData.nextPoisson(-1); Assert.fail("negative mean supplied -- MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } try { randomData.nextPoisson(0); Assert.fail("0 mean supplied -- MathIllegalArgumentException expected"); } catch (MathIllegalArgumentException ex) { } final double mean = 4.0d; final int len = 5; PoissonDistribution poissonDistribution = new PoissonDistribution(mean); Frequency f = new Frequency(); randomData.reSeed(1000); for (int i = 0; i < largeSampleSize; i++) { f.addValue(randomData.nextPoisson(mean)); } final long[] observed = new long[len]; for (int i = 0; i < len; i++) { observed[i] = f.getCount(i + 1); } final double[] expected = new double[len]; for (int i = 0; i < len; i++) { expected[i] = poissonDistribution.probability(i + 1) * largeSampleSize; } TestUtils.assertChiSquareAccept(expected, observed, 0.0001); }