Author: brentworden Date: Thu Apr 5 08:19:57 2007 New Revision: 525842 URL: http://svn.apache.org/viewvc?view=rev&rev=525842 Log: MATH-153: Corrected nextInt and nextLong to handle wide value ranges.
Modified: jakarta/commons/proper/math/trunk/ (props changed) jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/RandomDataTest.java jakarta/commons/proper/math/trunk/xdocs/changes.xml Propchange: jakarta/commons/proper/math/trunk/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Thu Apr 5 08:19:57 2007 @@ -1,10 +1,11 @@ -build.properties -target -dist -*.log -*.project -*.classpath -*.checkstyle -bin -.clover -junit*.properties +build.properties +target +dist +*.log +*.project +*.classpath +*.checkstyle +bin +.clover +junit*.properties +.settings Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java?view=diff&rev=525842&r1=525841&r2=525842 ============================================================================== --- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java (original) +++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/random/RandomDataImpl.java Thu Apr 5 08:19:57 2007 @@ -167,7 +167,8 @@ ("upper bound must be > lower bound"); } RandomGenerator rand = getRan(); - return lower + (int) (rand.nextDouble() * (upper - lower + 1)); + double r = rand.nextDouble(); + return (int)((r * upper) + ((1.0 - r) * lower) + r); } /** @@ -184,7 +185,8 @@ ("upper bound must be > lower bound"); } RandomGenerator rand = getRan(); - return lower + (long) (rand.nextDouble() * (upper - lower + 1)); + double r = rand.nextDouble(); + return (long)((r * upper) + ((1.0 - r) * lower) + r); } /** Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/RandomDataTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/RandomDataTest.java?view=diff&rev=525842&r1=525841&r2=525842 ============================================================================== --- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/RandomDataTest.java (original) +++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/random/RandomDataTest.java Thu Apr 5 08:19:57 2007 @@ -58,6 +58,18 @@ return suite; } + public void testNextIntExtremeValues() { + int x = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); + int y = randomData.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE); + assertFalse(x == y); + } + + public void testNextLongExtremeValues() { + long x = randomData.nextLong(Long.MIN_VALUE, Long.MAX_VALUE); + long y = randomData.nextLong(Long.MIN_VALUE, Long.MAX_VALUE); + assertFalse(x == y); + } + /** test dispersion and failure modes for nextInt() */ public void testNextInt() { try { Modified: jakarta/commons/proper/math/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/xdocs/changes.xml?view=diff&rev=525842&r1=525841&r2=525842 ============================================================================== --- jakarta/commons/proper/math/trunk/xdocs/changes.xml (original) +++ jakarta/commons/proper/math/trunk/xdocs/changes.xml Thu Apr 5 08:19:57 2007 @@ -71,6 +71,9 @@ Modified getSumSquaredErrors method in SimpleRegression to always return a non-negative result. </action> + <action dev="brentworden" type="fix" issue="MATH-153" due-to="Remi Arntzen"> + Corrected nextInt and nextLong to handle wide value ranges. + </action> </release> <release version="1.1" date="2005-12-17" description="This is a maintenance release containing bug fixes and enhancements. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]