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/24 18:29:47 UTC

[math] MATH-1301

Repository: commons-math
Updated Branches:
  refs/heads/master 2ab17f529 -> 9a87c766b


MATH-1301

Method "nextInt(int)" must throw a "NotStrictlyPositiveException" similarly to the other RNG implementations.
[Previous commit was incomplete.]


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

Branch: refs/heads/master
Commit: 9a87c766bb3137a50656871e5dee5a309543bc7d
Parents: 2ab17f5
Author: Gilles <er...@apache.org>
Authored: Thu Dec 24 18:29:01 2015 +0100
Committer: Gilles <er...@apache.org>
Committed: Thu Dec 24 18:29:01 2015 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                                  |  3 +++
 .../apache/commons/math4/random/JDKRandomGenerator.java  | 11 +++++++++++
 2 files changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/9a87c766/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c59d418..99ac52e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
     </release>
 
     <release version="4.0" date="XXXX-XX-XX" description="">
+      <action dev="erans" type="fix" issue="MATH-1301">
+        "JDKRandomGenerator": Method "nextInt(int)" now throws a "NotStrictlyPositiveException".
+      </action>
       <action dev="erans" type="update" issue="MATH-1305" due-to="Rostislav Krasny">
         "AbstractRandomGenerator" and "BitsStreamGenerator": Slight performance
         improvement of the "nextBytes" method (particularly when the number of

http://git-wip-us.apache.org/repos/asf/commons-math/blob/9a87c766/src/main/java/org/apache/commons/math4/random/JDKRandomGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/JDKRandomGenerator.java b/src/main/java/org/apache/commons/math4/random/JDKRandomGenerator.java
index 5e2e7c4..18f7466 100644
--- a/src/main/java/org/apache/commons/math4/random/JDKRandomGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/JDKRandomGenerator.java
@@ -17,6 +17,7 @@
 package org.apache.commons.math4.random;
 
 import java.util.Random;
+import org.apache.commons.math4.exception.NotStrictlyPositiveException;
 
 /**
  * Extension of <code>java.util.Random</code> to implement
@@ -57,4 +58,14 @@ public class JDKRandomGenerator extends Random implements RandomGenerator {
     public void setSeed(int[] seed) {
         setSeed(RandomGeneratorFactory.convertToLong(seed));
     }
+
+    /** {@inheritDoc} */
+    @Override
+    public int nextInt(int n) {
+        try {
+            return super.nextInt(n);
+        } catch (IllegalArgumentException e) {
+            throw new NotStrictlyPositiveException(n);
+        }
+    }
 }