implements Serializable {
* Creates a {@link Sampler}.
*
* @param rng Random number generator.
+ * @return a new sampler instance.
*/
public Sampler createSampler(final UniformRandomProvider rng) {
return new Sampler(rng);
diff --git a/src/main/java/org/apache/commons/math4/distribution/EnumeratedRealDistribution.java b/src/main/java/org/apache/commons/math4/distribution/EnumeratedRealDistribution.java
index 7cf834bd4..0e34f5a8f 100644
--- a/src/main/java/org/apache/commons/math4/distribution/EnumeratedRealDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/EnumeratedRealDistribution.java
@@ -273,15 +273,6 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
return true;
}
- /**
- * {@inheritDoc}
- */
- @Override
- @Deprecated
- public double sample() {
- return innerDistribution.sample();
- }
-
/** {@inheritDoc} */
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
diff --git a/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java b/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java
index 1dbd6b181..9527aa00b 100644
--- a/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/ExponentialDistribution.java
@@ -186,58 +186,6 @@ public class ExponentialDistribution extends AbstractRealDistribution {
return ret;
}
- /**
- * {@inheritDoc}
- *
- * Algorithm Description: this implementation uses the
- *
- * Inversion Method to generate exponentially distributed random values
- * from uniform deviates.
- *
- * @return a random value.
- * @since 2.2
- */
- @Override
- @Deprecated
- public double sample() {
- // Step 1:
- double a = 0;
- double u = random.nextDouble();
-
- // Step 2 and 3:
- while (u < 0.5) {
- a += EXPONENTIAL_SA_QI[0];
- u *= 2;
- }
-
- // Step 4 (now u >= 0.5):
- u += u - 1;
-
- // Step 5:
- if (u <= EXPONENTIAL_SA_QI[0]) {
- return mean * (a + u);
- }
-
- // Step 6:
- int i = 0; // Should be 1, be we iterate before it in while using 0
- double u2 = random.nextDouble();
- double umin = u2;
-
- // Step 7 and 8:
- do {
- ++i;
- u2 = random.nextDouble();
-
- if (u2 < umin) {
- umin = u2;
- }
-
- // Step 8:
- } while (u > EXPONENTIAL_SA_QI[i]); // Ensured to exit since EXPONENTIAL_SA_QI[MAX] = 1
-
- return mean * (a + umin * EXPONENTIAL_SA_QI[0]);
- }
-
/** {@inheritDoc} */
@Override
protected double getSolverAbsoluteAccuracy() {
diff --git a/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java b/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java
index c50c9742a..413493f31 100644
--- a/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java
@@ -350,88 +350,6 @@ public class GammaDistribution extends AbstractRealDistribution {
return true;
}
- /**
- * This implementation uses the following algorithms:
- *
- * For 0 < shape < 1:
- * Ahrens, J. H. and Dieter, U., Computer methods for
- * sampling from gamma, beta, Poisson and binomial distributions.
- * Computing, 12, 223-246, 1974.
- *
- * For shape >= 1:
- * Marsaglia and Tsang, A Simple Method for Generating
- * Gamma Variables. ACM Transactions on Mathematical Software,
- * Volume 26 Issue 3, September, 2000.
- *
- * @return random value sampled from the Gamma(shape, scale) distribution
- */
- @Override
- @Deprecated
- public double sample() {
- if (shape < 1) {
- // [1]: p. 228, Algorithm GS
-
- while (true) {
- // Step 1:
- final double u = random.nextDouble();
- final double bGS = 1 + shape / FastMath.E;
- final double p = bGS * u;
-
- if (p <= 1) {
- // Step 2:
-
- final double x = FastMath.pow(p, 1 / shape);
- final double u2 = random.nextDouble();
-
- if (u2 > FastMath.exp(-x)) {
- // Reject
- continue;
- } else {
- return scale * x;
- }
- } else {
- // Step 3:
-
- final double x = -1 * FastMath.log((bGS - p) / shape);
- final double u2 = random.nextDouble();
-
- if (u2 > FastMath.pow(x, shape - 1)) {
- // Reject
- continue;
- } else {
- return scale * x;
- }
- }
- }
- }
-
- // Now shape >= 1
-
- final double d = shape - 0.333333333333333333;
- final double c = 1 / (3 * FastMath.sqrt(d));
-
- while (true) {
- final double x = random.nextGaussian();
- final double v = (1 + c * x) * (1 + c * x) * (1 + c * x);
-
- if (v <= 0) {
- continue;
- }
-
- final double x2 = x * x;
- final double u = random.nextDouble();
-
- // Squeeze
- if (u < 1 - 0.0331 * x2 * x2) {
- return scale * d * v;
- }
-
- if (FastMath.log(u) < 0.5 * x2 + d * (1 - v + FastMath.log(v))) {
- return scale * d * v;
- }
- }
- }
-
/**
* {@inheritDoc}
*
@@ -461,7 +379,7 @@ public class GammaDistribution extends AbstractRealDistribution {
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
/** Gaussian sampling. */
- final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
+ private final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
/** {@inheritDoc} */
@Override
diff --git a/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java b/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
index eafb90e8f..6b155d51e 100644
--- a/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
@@ -288,25 +288,17 @@ public class LogNormalDistribution extends AbstractRealDistribution {
return true;
}
- /** {@inheritDoc} */
- @Override
- @Deprecated
- public double sample() {
- final double n = random.nextGaussian();
- return FastMath.exp(scale + shape * n);
- }
-
/** {@inheritDoc} */
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
return new RealDistribution.Sampler() {
/** Gaussian sampling. */
- final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
+ private final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
/** {@inheritDoc} */
@Override
public double sample() {
- final double n = random.nextGaussian();
+ final double n = gaussian.sample();
return FastMath.exp(scale + shape * n);
}
};
diff --git a/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java b/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java
index a8330d5e7..b8e919b1f 100644
--- a/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/NormalDistribution.java
@@ -235,13 +235,6 @@ public class NormalDistribution extends AbstractRealDistribution {
return true;
}
- /** {@inheritDoc} */
- @Override
- @Deprecated
- public double sample() {
- return standardDeviation * random.nextGaussian() + mean;
- }
-
/** {@inheritDoc} */
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
diff --git a/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java b/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java
index 217432231..04427dacb 100644
--- a/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/ParetoDistribution.java
@@ -248,14 +248,6 @@ public class ParetoDistribution extends AbstractRealDistribution {
return true;
}
- /** {@inheritDoc} */
- @Override
- @Deprecated
- public double sample() {
- final double n = random.nextDouble();
- return scale / FastMath.pow(n, 1 / shape);
- }
-
/** {@inheritDoc} */
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
diff --git a/src/main/java/org/apache/commons/math4/distribution/RealDistribution.java b/src/main/java/org/apache/commons/math4/distribution/RealDistribution.java
index f0e453aa6..7ddc1fd22 100644
--- a/src/main/java/org/apache/commons/math4/distribution/RealDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/RealDistribution.java
@@ -160,33 +160,6 @@ public interface RealDistribution {
*/
boolean isSupportConnected();
- /**
- * Reseed the random generator used to generate samples.
- *
- * @param seed the new seed
- */
- @Deprecated
- void reseedRandomGenerator(long seed);
-
- /**
- * Generate a random value sampled from this distribution.
- *
- * @return a random value.
- */
- @Deprecated
- double sample();
-
- /**
- * Generate a random sample from the distribution.
- *
- * @param sampleSize the number of random values to generate
- * @return an array representing the random sample
- * @throws org.apache.commons.math4.exception.NotStrictlyPositiveException
- * if {@code sampleSize} is not positive
- */
- @Deprecated
- double[] sample(int sampleSize);
-
/**
* Creates a sampler.
*
diff --git a/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java b/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java
index 404cc0286..a7a1c4d9e 100644
--- a/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/UniformRealDistribution.java
@@ -158,14 +158,6 @@ public class UniformRealDistribution extends AbstractRealDistribution {
return true;
}
- /** {@inheritDoc} */
- @Override
- @Deprecated
- public double sample() {
- final double u = random.nextDouble();
- return u * upper + (1 - u) * lower;
- }
-
/** {@inheritDoc} */
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
diff --git a/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java b/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java
index 926ad093c..fad5226af 100644
--- a/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java
+++ b/src/main/java/org/apache/commons/math4/random/EmpiricalDistribution.java
@@ -42,7 +42,6 @@ import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.stat.descriptive.StatisticalSummary;
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
import org.apache.commons.math4.rng.UniformRandomProvider;
-import org.apache.commons.math4.rng.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathUtils;
@@ -113,10 +112,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
/** Serializable version identifier */
private static final long serialVersionUID = 5729073523949762654L;
- /** RandomDataGenerator instance to use in repeated calls to getNext() */
- @Deprecated
- protected final RandomDataGenerator randomData;
-
/** List of SummaryStatistics objects characterizing the bins */
private final List binStats;
@@ -160,54 +155,8 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
}
this.binCount = binCount;
binStats = new ArrayList();
- randomData = null; // XXX remove
}
- /**
- * Creates a new EmpiricalDistribution with the specified bin count using the
- * provided {@link RandomGenerator} as the source of random data.
- *
- * @param binCount number of bins. Must be strictly positive.
- * @param generator random data generator (may be null, resulting in default JDK generator)
- * @throws NotStrictlyPositiveException if {@code binCount <= 0}.
- * @since 3.0
- */
- @Deprecated
- public EmpiricalDistribution(int binCount, RandomGenerator generator) {
- this(binCount, new RandomDataGenerator(generator));
- }
-
- /**
- * Creates a new EmpiricalDistribution with default bin count using the
- * provided {@link RandomGenerator} as the source of random data.
- *
- * @param generator random data generator (may be null, resulting in default JDK generator)
- * @since 3.0
- */
- @Deprecated
- public EmpiricalDistribution(RandomGenerator generator) {
- this(DEFAULT_BIN_COUNT, generator);
- }
-
- /**
- * Private constructor to allow lazy initialisation of the RNG contained
- * in the {@link #randomData} instance variable.
- *
- * @param binCount number of bins. Must be strictly positive.
- * @param randomData Random data generator.
- * @throws NotStrictlyPositiveException if {@code binCount <= 0}.
- */
- @Deprecated
- private EmpiricalDistribution(int binCount,
- RandomDataGenerator randomData) {
- if (binCount <= 0) {
- throw new NotStrictlyPositiveException(binCount);
- }
- this.binCount = binCount;
- this.randomData = randomData;
- binStats = new ArrayList();
- }
-
/**
* Computes the empirical distribution from the provided
* array of numbers.
@@ -455,21 +404,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
binCount - 1);
}
- /**
- * Generates a random value from this distribution.
- * Preconditions:
- * - the distribution must be loaded before invoking this method
- * @return the random value.
- * @throws MathIllegalStateException if the distribution has not been loaded
- */
- @Deprecated
- public double getNextValue() throws MathIllegalStateException {
- if (!loaded) {
- throw new MathIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED);
- }
- return sample();
- }
-
/**
* Returns a {@link StatisticalSummary} describing this distribution.
* Preconditions:
@@ -556,18 +490,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
return loaded;
}
- /**
- * Reseeds the random number generator used by {@link #getNextValue()}.
- *
- * @param seed random generator seed
- * @since 3.0
- * XXX REMOVE
- */
- @Deprecated
- public void reSeed(long seed) {
- randomData.reSeed(seed);
- }
-
// Distribution methods ---------------------------
/**
@@ -742,16 +664,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
return true;
}
- /**
- * {@inheritDoc}
- * @since 3.1
- */
- @Override
- @Deprecated
- public void reseedRandomGenerator(long seed) {
- randomData.reSeed(seed);
- }
-
/**{@inheritDoc} */
@Override
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
diff --git a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
index b75de0e8e..79451dd55 100644
--- a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
+++ b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
@@ -160,7 +160,8 @@ public class KolmogorovSmirnovTest {
* The #monteCarloP(double, int, int, boolean, int) that uses the generator supplied to this
* constructor is deprecated as of version 3.6.
*
- * @param rng random data generator used by {@link #monteCarloP(double, int, int, boolean, int)}
+ * @param source random data generator used by {@link #monteCarloP(double, int, int, boolean, int)}
+ * @param seed Seed.
*/
@Deprecated
public KolmogorovSmirnovTest(RandomSource source,
@@ -1209,10 +1210,8 @@ public class KolmogorovSmirnovTest {
private static void jitter(double[] data, RealDistribution.Sampler sampler) {
for (int i = 0; i < data.length; i++) {
final double d = sampler.sample();
- System.out.println("d=" + d); // XXX
data[i] += d;
}
- System.out.println(); // XXX
}
/**
diff --git a/src/test/java/org/apache/commons/math4/fitting/PolynomialCurveFitterTest.java b/src/test/java/org/apache/commons/math4/fitting/PolynomialCurveFitterTest.java
index 89ebc2b95..2b1e2d3f1 100644
--- a/src/test/java/org/apache/commons/math4/fitting/PolynomialCurveFitterTest.java
+++ b/src/test/java/org/apache/commons/math4/fitting/PolynomialCurveFitterTest.java
@@ -26,6 +26,7 @@ import org.apache.commons.math4.exception.ConvergenceException;
import org.apache.commons.math4.fitting.PolynomialCurveFitter;
import org.apache.commons.math4.fitting.WeightedObservedPoints;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.rng.RandomSource;
import org.junit.Assert;
import org.junit.Test;
@@ -35,9 +36,9 @@ import org.junit.Test;
public class PolynomialCurveFitterTest {
@Test
public void testFit() {
- final RealDistribution rng = new UniformRealDistribution(-100, 100);
- rng.reseedRandomGenerator(64925784252L);
-
+ final RealDistribution.Sampler rng
+ = new UniformRealDistribution(-100, 100).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784252L));
final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
final PolynomialFunction f = new PolynomialFunction(coeff);
diff --git a/src/test/java/org/apache/commons/math4/fitting/SimpleCurveFitterTest.java b/src/test/java/org/apache/commons/math4/fitting/SimpleCurveFitterTest.java
index 01d28b2a3..4a3867c51 100644
--- a/src/test/java/org/apache/commons/math4/fitting/SimpleCurveFitterTest.java
+++ b/src/test/java/org/apache/commons/math4/fitting/SimpleCurveFitterTest.java
@@ -25,6 +25,7 @@ import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.UniformRealDistribution;
import org.apache.commons.math4.fitting.SimpleCurveFitter;
import org.apache.commons.math4.fitting.WeightedObservedPoints;
+import org.apache.commons.math4.rng.RandomSource;
import org.junit.Test;
/**
@@ -34,8 +35,9 @@ public class SimpleCurveFitterTest {
@Test
public void testPolynomialFit() {
final Random randomizer = new Random(53882150042L);
- final RealDistribution rng = new UniformRealDistribution(-100, 100);
- rng.reseedRandomGenerator(64925784252L);
+ final RealDistribution.Sampler rng
+ = new UniformRealDistribution(-100, 100).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784253L));
final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
final PolynomialFunction f = new PolynomialFunction(coeff);
diff --git a/src/test/java/org/apache/commons/math4/linear/EigenDecompositionTest.java b/src/test/java/org/apache/commons/math4/linear/EigenDecompositionTest.java
index fba9e9089..683954f65 100644
--- a/src/test/java/org/apache/commons/math4/linear/EigenDecompositionTest.java
+++ b/src/test/java/org/apache/commons/math4/linear/EigenDecompositionTest.java
@@ -20,6 +20,7 @@ package org.apache.commons.math4.linear;
import java.util.Arrays;
import java.util.Random;
+import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.NormalDistribution;
import org.apache.commons.math4.exception.MathUnsupportedOperationException;
import org.apache.commons.math4.linear.ArrayRealVector;
@@ -32,6 +33,7 @@ import org.apache.commons.math4.linear.TriDiagonalTransformer;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathArrays;
import org.apache.commons.math4.util.Precision;
+import org.apache.commons.math4.rng.RandomSource;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -468,7 +470,9 @@ public class EigenDecompositionTest {
public void testNormalDistributionUnsymmetricMatrix() {
for (int run = 0; run < 100; run++) {
Random r = new Random(System.currentTimeMillis());
- NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);
+ RealDistribution.Sampler dist
+ = new NormalDistribution(0.0, r.nextDouble() * 5).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784252L));
// matrix size
int size = r.nextInt(20) + 4;
diff --git a/src/test/java/org/apache/commons/math4/linear/HessenbergTransformerTest.java b/src/test/java/org/apache/commons/math4/linear/HessenbergTransformerTest.java
index 310f23de7..af6e83731 100644
--- a/src/test/java/org/apache/commons/math4/linear/HessenbergTransformerTest.java
+++ b/src/test/java/org/apache/commons/math4/linear/HessenbergTransformerTest.java
@@ -19,11 +19,13 @@ package org.apache.commons.math4.linear;
import java.util.Random;
+import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.NormalDistribution;
import org.apache.commons.math4.linear.HessenbergTransformer;
import org.apache.commons.math4.linear.MatrixUtils;
import org.apache.commons.math4.linear.NonSquareMatrixException;
import org.apache.commons.math4.linear.RealMatrix;
+import org.apache.commons.math4.rng.RandomSource;
import org.junit.Test;
import org.junit.Assert;
@@ -112,7 +114,9 @@ public class HessenbergTransformerTest {
public void testRandomDataNormalDistribution() {
for (int run = 0; run < 100; run++) {
Random r = new Random(System.currentTimeMillis());
- NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);
+ RealDistribution.Sampler dist
+ = new NormalDistribution(0.0, r.nextDouble() * 5).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784252L));
// matrix size
int size = r.nextInt(20) + 4;
diff --git a/src/test/java/org/apache/commons/math4/linear/SchurTransformerTest.java b/src/test/java/org/apache/commons/math4/linear/SchurTransformerTest.java
index e0a5611a4..f2cf72ee0 100644
--- a/src/test/java/org/apache/commons/math4/linear/SchurTransformerTest.java
+++ b/src/test/java/org/apache/commons/math4/linear/SchurTransformerTest.java
@@ -19,11 +19,13 @@ package org.apache.commons.math4.linear;
import java.util.Random;
+import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.NormalDistribution;
import org.apache.commons.math4.linear.MatrixUtils;
import org.apache.commons.math4.linear.NonSquareMatrixException;
import org.apache.commons.math4.linear.RealMatrix;
import org.apache.commons.math4.linear.SchurTransformer;
+import org.apache.commons.math4.rng.RandomSource;
import org.junit.Test;
import org.junit.Assert;
@@ -116,7 +118,9 @@ public class SchurTransformerTest {
public void testRandomDataNormalDistribution() {
for (int run = 0; run < 100; run++) {
Random r = new Random(System.currentTimeMillis());
- NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);
+ RealDistribution.Sampler dist
+ = new NormalDistribution(0.0, r.nextDouble() * 5).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784252L));
// matrix size
int size = r.nextInt(20) + 4;
diff --git a/src/test/java/org/apache/commons/math4/stat/descriptive/AggregateSummaryStatisticsTest.java b/src/test/java/org/apache/commons/math4/stat/descriptive/AggregateSummaryStatisticsTest.java
index 5324ecf4f..139a06023 100644
--- a/src/test/java/org/apache/commons/math4/stat/descriptive/AggregateSummaryStatisticsTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/descriptive/AggregateSummaryStatisticsTest.java
@@ -23,9 +23,11 @@ import java.util.Collection;
import org.apache.commons.math4.TestUtils;
import org.apache.commons.math4.distribution.IntegerDistribution;
import org.apache.commons.math4.distribution.RealDistribution;
+import org.apache.commons.math4.distribution.AbstractRealDistribution;
import org.apache.commons.math4.distribution.UniformIntegerDistribution;
import org.apache.commons.math4.distribution.UniformRealDistribution;
import org.apache.commons.math4.util.Precision;
+import org.apache.commons.math4.rng.RandomSource;
import org.junit.Assert;
import org.junit.Test;
@@ -281,9 +283,11 @@ public class AggregateSummaryStatisticsTest {
*/
private double[] generateSample() {
final IntegerDistribution size = new UniformIntegerDistribution(10, 100);
- final RealDistribution randomData = new UniformRealDistribution(-100, 100);
+ final RealDistribution.Sampler randomData
+ = new UniformRealDistribution(-100, 100).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784252L));;
final int sampleSize = size.sample();
- final double[] out = randomData.sample(sampleSize);
+ final double[] out = AbstractRealDistribution.sample(sampleSize, randomData);
return out;
}
diff --git a/src/test/java/org/apache/commons/math4/stat/descriptive/UnivariateStatisticAbstractTest.java b/src/test/java/org/apache/commons/math4/stat/descriptive/UnivariateStatisticAbstractTest.java
index 6f12b1e18..cd5be562f 100644
--- a/src/test/java/org/apache/commons/math4/stat/descriptive/UnivariateStatisticAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/descriptive/UnivariateStatisticAbstractTest.java
@@ -27,6 +27,7 @@ import org.apache.commons.math4.distribution.UniformIntegerDistribution;
import org.apache.commons.math4.stat.descriptive.UnivariateStatistic;
import org.apache.commons.math4.stat.descriptive.WeightedEvaluation;
import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.rng.RandomSource;
import org.junit.Assert;
import org.junit.Test;
@@ -187,7 +188,9 @@ public abstract class UnivariateStatisticAbstractTest {
// Fill values array with random data from N(mu, sigma)
// and fill valuesList with values from values array with
// values[i] repeated weights[i] times, each i
- final RealDistribution valueDist = new NormalDistribution(mu, sigma);
+ final RealDistribution.Sampler valueDist
+ = new NormalDistribution(mu, sigma).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784252L));
List valuesList = new ArrayList();
for (int i = 0; i < len; i++) {
double value = valueDist.sample();
diff --git a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java
index fdbf689f0..52cea3349 100644
--- a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java
@@ -27,6 +27,7 @@ import java.util.Set;
import org.apache.commons.math4.distribution.LogNormalDistribution;
import org.apache.commons.math4.distribution.NormalDistribution;
import org.apache.commons.math4.distribution.RealDistribution;
+import org.apache.commons.math4.distribution.AbstractRealDistribution;
import org.apache.commons.math4.exception.MathIllegalArgumentException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.OutOfRangeException;
@@ -714,39 +715,39 @@ public class PSquarePercentileTest extends
distribution.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
double data[];
- data = distribution.sample(VERY_LARGE);
+ data = AbstractRealDistribution.sample(VERY_LARGE, sampler);
doCalculatePercentile(50, data, 0.0001);
doCalculatePercentile(95, data, 0.0001);
- data = distribution.sample(LARGE);
+ data = AbstractRealDistribution.sample(LARGE, sampler);
doCalculatePercentile(50, data, 0.001);
doCalculatePercentile(95, data, 0.001);
- data = distribution.sample(VERY_BIG);
+ data = AbstractRealDistribution.sample(VERY_BIG, sampler);
doCalculatePercentile(50, data, 0.001);
doCalculatePercentile(95, data, 0.001);
- data = distribution.sample(BIG);
+ data = AbstractRealDistribution.sample(BIG, sampler);
doCalculatePercentile(50, data, 0.001);
doCalculatePercentile(95, data, 0.001);
- data = distribution.sample(STANDARD);
+ data = AbstractRealDistribution.sample(STANDARD, sampler);
doCalculatePercentile(50, data, 0.005);
doCalculatePercentile(95, data, 0.005);
- data = distribution.sample(MEDIUM);
+ data = AbstractRealDistribution.sample(MEDIUM, sampler);
doCalculatePercentile(50, data, 0.005);
doCalculatePercentile(95, data, 0.005);
- data = distribution.sample(NOMINAL);
+ data = AbstractRealDistribution.sample(NOMINAL, sampler);
doCalculatePercentile(50, data, 0.01);
doCalculatePercentile(95, data, 0.01);
- data = distribution.sample(SMALL);
+ data = AbstractRealDistribution.sample(SMALL, sampler);
doCalculatePercentile(50, data, 0.01);
doCalculatePercentile(95, data, 0.01);
- data = distribution.sample(TINY);
+ data = AbstractRealDistribution.sample(TINY, sampler);
doCalculatePercentile(50, data, 0.05);
doCalculatePercentile(95, data, 0.05);
diff --git a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
index b9beee369..8ce9a2d48 100644
--- a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
+++ b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
@@ -20,6 +20,7 @@ import org.apache.commons.math4.exception.NotFiniteNumberException;
import org.apache.commons.math4.exception.NullArgumentException;
import org.apache.commons.math4.exception.util.LocalizedFormats;
import org.apache.commons.math4.random.RandomDataGenerator;
+import org.apache.commons.math4.rng.RandomSource;
import org.apache.commons.math4.util.FastMath;
import org.apache.commons.math4.util.MathUtils;
import org.junit.Assert;
@@ -100,7 +101,9 @@ public final class MathUtilsTest {
// Generate 10 distinct random values
for (int i = 0; i < 10; i++) {
- final RealDistribution u = new UniformRealDistribution(i + 0.5, i + 0.75);
+ final RealDistribution.Sampler u
+ = new UniformRealDistribution(i + 0.5, i + 0.75).createSampler(RandomSource.create(RandomSource.WELL_512_A,
+ 64925784252L));
original[i] = u.sample();
}