[
https://issues.apache.org/jira/browse/MATH-153?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Brent Worden resolved MATH-153.
-------------------------------
Resolution: Fixed
Fix Version/s: 1.2
SVN 525842: Corrected nextInt and nextLong to handle wide value ranges.
> RandomDataImpl nextInt(int, int) nextLong(long, long)
> -----------------------------------------------------
>
> Key: MATH-153
> URL: https://issues.apache.org/jira/browse/MATH-153
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 1.1, Nightly Builds
> Reporter: Remi Arntzen
> Priority: Critical
> Fix For: 1.2
>
> Attachments: diff.txt, Test.diff
>
>
> RandomDataImpl.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE) suffers from
> overflow errors.
> change
> return lower + (int) (rand.nextDouble() * (upper - lower + 1));
> to
> return (int) (lower + (long) (rand.nextDouble()*((long) upper - lower + 1)));
> additional checks must be made for the nextlong(long, long) method.
> At first I thought about using MathUtils.subAndCheck(long, long) but there is
> only an int version avalible, and the problem is that subAndCheck internaly
> uses long values to check for overflow just as my previous channge proposes.
> The only thing I can think of is using a BigInteger to check for the number
> of bits required to express the difference.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]