You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/08/05 16:45:55 UTC

[commons-rng] 04/21: Pass UniformRandomProvider to the integrator

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit fb46d54f9c252b687079f46ae489b4a019945fa9
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Aug 5 13:39:18 2021 +0100

    Pass UniformRandomProvider to the integrator
---
 .../org/apache/commons/rng/examples/quadrature/ComputePi.java    | 9 +++++----
 .../commons/rng/examples/quadrature/MonteCarloIntegration.java   | 7 +++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/ComputePi.java b/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/ComputePi.java
index 56eceb2..829895f 100644
--- a/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/ComputePi.java
+++ b/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/ComputePi.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.rng.examples.quadrature;
 
+import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.rng.simple.RandomSource;
 
 /**
@@ -39,10 +40,10 @@ public class ComputePi extends MonteCarloIntegration {
     private static final int DIMENSION = 2;
 
     /**
-     * @param source RNG algorithm.
+     * @param rng RNG.
      */
-    public ComputePi(RandomSource source) {
-        super(source, DIMENSION);
+    public ComputePi(UniformRandomProvider rng) {
+        super(rng, DIMENSION);
     }
 
     /**
@@ -67,7 +68,7 @@ public class ComputePi extends MonteCarloIntegration {
         final long numPoints = Long.parseLong(args[0]);
         final RandomSource randomSource = RandomSource.valueOf(args[1]);
 
-        final ComputePi piApp = new ComputePi(randomSource);
+        final ComputePi piApp = new ComputePi(randomSource.create());
         final double piMC = piApp.compute(numPoints);
 
         //CHECKSTYLE: stop all
diff --git a/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java b/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java
index fe43df7..ff775d3 100644
--- a/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java
+++ b/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java
@@ -18,7 +18,6 @@
 package org.apache.commons.rng.examples.quadrature;
 
 import org.apache.commons.rng.UniformRandomProvider;
-import org.apache.commons.rng.simple.RandomSource;
 
 /**
  * <a href="https://en.wikipedia.org/wiki/Monte_Carlo_integration">Monte-Carlo method</a>
@@ -33,12 +32,12 @@ public abstract class MonteCarloIntegration {
     /**
      * Simulation constructor.
      *
-     * @param source RNG algorithm.
+     * @param rng RNG.
      * @param dimension Integration domain dimension.
      */
-    public MonteCarloIntegration(RandomSource source,
+    public MonteCarloIntegration(UniformRandomProvider rng,
                                  int dimension) {
-        this.rng = source.create();
+        this.rng = rng;
         this.dimension = dimension;
     }