You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2015/12/28 18:23:22 UTC

[10/18] [math] MATH-1309

MATH-1309

Not calling public "setSeed" from a constructor.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/e0d17fed
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/e0d17fed
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/e0d17fed

Branch: refs/heads/master
Commit: e0d17fed51f5018fc34578699d824c20efc44368
Parents: 581b474
Author: Gilles <er...@apache.org>
Authored: Mon Dec 28 17:11:31 2015 +0100
Committer: Gilles <er...@apache.org>
Committed: Mon Dec 28 17:32:56 2015 +0100

----------------------------------------------------------------------
 .../commons/math4/random/ISAACRandom.java       | 41 ++++++++++++++++----
 1 file changed, 34 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/e0d17fed/src/main/java/org/apache/commons/math4/random/ISAACRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/ISAACRandom.java b/src/main/java/org/apache/commons/math4/random/ISAACRandom.java
index b9c0e36..185710f 100644
--- a/src/main/java/org/apache/commons/math4/random/ISAACRandom.java
+++ b/src/main/java/org/apache/commons/math4/random/ISAACRandom.java
@@ -85,7 +85,7 @@ public class ISAACRandom
      * current time and system hash code of the instance as the seed.
      */
     public ISAACRandom() {
-        setSeed(System.currentTimeMillis() + System.identityHashCode(this));
+        setSeedInternal(System.currentTimeMillis() + System.identityHashCode(this));
     }
 
     /**
@@ -94,7 +94,7 @@ public class ISAACRandom
      * @param seed Initial seed.
      */
     public ISAACRandom(long seed) {
-        setSeed(seed);
+        setSeedInternal(seed);
     }
 
     /**
@@ -104,24 +104,51 @@ public class ISAACRandom
      * to the current time.
      */
     public ISAACRandom(int[] seed) {
-        setSeed(seed);
+        setSeedInternal(seed);
     }
 
     /** {@inheritDoc} */
     @Override
     public void setSeed(int seed) {
-        setSeed(new int[]{seed});
+        setSeedInternal(seed);
     }
 
     /** {@inheritDoc} */
     @Override
-    public void setSeed(long seed) {
-        setSeed(new int[]{(int) (seed >>> 32), (int) (seed & 0xffffffffL)});
+    public void setSeed(int[] seed) {
+        setSeedInternal(seed);
     }
 
     /** {@inheritDoc} */
     @Override
-    public void setSeed(int[] seed) {
+    public void setSeed(long seed) {
+        setSeedInternal(seed);
+    }
+
+    /**
+     * Reseeds the RNG.
+     *
+     * @param seed Seed.
+     */
+    private void setSeedInternal(int seed) {
+        setSeed(new int[]{seed});
+    }
+
+    /**
+     * Reseeds the RNG.
+     *
+     * @param seed Seed.
+     */
+    private void setSeedInternal(long seed) {
+        setSeed(new int[]{(int) (seed >>> 32), (int) (seed & 0xffffffffL)});
+    }
+
+    /**
+     * Reseeds the RNG.
+     *
+     * @param seed Seed.
+     */
+    private void setSeedInternal(int[] seed) {
         if (seed == null) {
             setSeed(System.currentTimeMillis() + System.identityHashCode(this));
             return;