commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1153338 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/random/AbstractRandomGenerator.java site/xdoc/changes.xml test/java/org/apache/commons/math/random/AbstractRandomGeneratorTest.java
Date Wed, 03 Aug 2011 04:16:24 GMT
Author: psteitz
Date: Wed Aug  3 04:16:23 2011
New Revision: 1153338

URL: http://svn.apache.org/viewvc?rev=1153338&view=rev
Log:
Fixed bugs in AbstractRandomGenerator nextInt() and nextLong() default
implementations.  Prior to the fix for this issue, these methods
generated only positive values.

JIRA: MATH-640

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/AbstractRandomGeneratorTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java?rev=1153338&r1=1153337&r2=1153338&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/AbstractRandomGenerator.java
Wed Aug  3 04:16:23 2011
@@ -134,7 +134,7 @@ public abstract class AbstractRandomGene
      *  value from this random number generator's sequence
      */
     public int nextInt() {
-        return (int) (nextDouble() * Integer.MAX_VALUE);
+        return (int) ((2d * nextDouble() - 1d) * Integer.MAX_VALUE);
     }
 
     /**
@@ -176,7 +176,7 @@ public abstract class AbstractRandomGene
      *value from this random number generator's sequence
      */
     public long nextLong() {
-        return (long) (nextDouble() * Long.MAX_VALUE);
+        return (long) ((2d * nextDouble() - 1d) * Long.MAX_VALUE);
     }
 
     /**

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1153338&r1=1153337&r2=1153338&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Wed Aug  3 04:16:23 2011
@@ -52,6 +52,11 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="psteitz" type="fix" issue="MATH-640">
+        Fixed bugs in AbstractRandomGenerator nextInt() and nextLong() default
+        implementations.  Prior to the fix for this issue, these methods
+        generated only positive values.
+      </action>
       <action dev="erans" type="add" issue="MATH-637">
         Simple benchmark utility (new class "PerfTestUtils" added to test sources in src/test).
       </action>

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/AbstractRandomGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/AbstractRandomGeneratorTest.java?rev=1153338&r1=1153337&r2=1153338&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/AbstractRandomGeneratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/AbstractRandomGeneratorTest.java
Wed Aug  3 04:16:23 2011
@@ -23,16 +23,6 @@ package org.apache.commons.math.random;
  */
 
 public class AbstractRandomGeneratorTest extends RandomGeneratorAbstractTest {
-    
-    @Override
-    public void testNextInt2() {
-        // Currently broken.  Remove this stub when MATH-640 is resolved
-    }
-    
-    @Override
-    public void testNextLong2() {
-        // Currently broken.  Remove this stub when MATH-640 is resolved
-    }
 
     public AbstractRandomGeneratorTest() {
         super();
@@ -40,7 +30,7 @@ public class AbstractRandomGeneratorTest
     
     protected RandomGenerator makeGenerator() {
         RandomGenerator generator = new TestRandomGenerator();
-        generator.setSeed(1000);
+        generator.setSeed(1001);
         return generator;
     }
     



Mime
View raw message