diff --git a/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java index d3e167d4b..373271d0c 100644 --- a/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java +++ b/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java @@ -321,12 +321,14 @@ public class BetaDistributionTest { @Test public void testMomentsSampling() { - RandomGenerator random = new Well1024a(0x7829862c82fec2dal); + final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_1024_A, + 123456789L); final int numSamples = 1000; for (final double alpha : alphaBetas) { for (final double beta : alphaBetas) { - final BetaDistribution betaDistribution = new BetaDistribution(random, alpha, beta); - final double[] observed = new BetaDistribution(alpha, beta).sample(numSamples); + final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); + final double[] observed = AbstractRealDistribution.sample(numSamples, + betaDistribution.createSampler(rng)); Arrays.sort(observed); final String distribution = String.format("Beta(%.2f, %.2f)", alpha, beta); @@ -353,11 +355,7 @@ public class BetaDistributionTest { final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta); final RealDistribution.Sampler sampler = betaDistribution.createSampler(rng); - final double[] observed = new double[numSamples]; - - for (int i = 0; i < numSamples; i++) { - observed[i] = sampler.sample(); - } + final double[] observed = AbstractRealDistribution.sample(numSamples, sampler); Assert.assertFalse("G goodness-of-fit test rejected null at alpha = " + level, gTest(betaDistribution, observed) < level); diff --git a/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java b/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java index fa1542fbe..61d01ffeb 100644 --- a/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java +++ b/src/test/java/org/apache/commons/math4/distribution/RealDistributionAbstractTest.java @@ -347,12 +347,7 @@ public abstract class RealDistributionAbstractTest { final int sampleSize = 1000; final RealDistribution.Sampler sampler = distribution.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 123456789L)); - - final double[] sample = new double[sampleSize]; - for (int i = 0; i < sampleSize; i++) { - sample[i] = sampler.sample(); - } - + final double[] sample = AbstractRealDistribution.sample(sampleSize, sampler); final double[] quartiles = TestUtils.getDistributionQuartiles(distribution); final double[] expected = {250, 250, 250, 250}; final long[] counts = new long[4];