[
https://issues.apache.org/jira/browse/MATH-724?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dennis Hendriks updated MATH-724:
---------------------------------
Attachment: math-724-v2.patch
math-724-v2.patch: 2nd patch.
- I think all unit tests work now, including the ones for the
Integer.MIN_VALUE to Integer.MAX_VALUE interval.
- The original problem was that negative values were rounded up by the
conversion from double to int, while positive numbers were rounded down. By
using floor, we first round the numbers down, and then convert to integer, thus
ensuring a proper uniform distribution.
- Test cases for negative values are still missing... Could someone else add
them?
- RandomDataImpl.nextUniform: I haven't changed this, as the change that I
used for integers does not have the desired effect for doubles... This may be
caused by the fact that Double.MIN_VALUE is more negative than Double.MAX_VALUE
is positive, but I'm not really sure. Maybe it is not even an issue for the
nextUniform method?
> RandomDataImpl.nextInt does not distribute uniformly for negative lower bound
> -----------------------------------------------------------------------------
>
> Key: MATH-724
> URL: https://issues.apache.org/jira/browse/MATH-724
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: Nightly Builds
> Reporter: Dennis Hendriks
> Attachments: NextIntUniformTest.java, math-724-v2.patch,
> math-724.patch
>
>
> When using the RandomDataImpl.nextInt function to get a uniform sample in a
> [lower, upper] interval, when the lower value is less than zero, the output
> is not uniformly distributed, as the lowest value is practically never
> returned.
> See the attached NextIntUniformTest.java file. It uses a [-3, 5] interval.
> For several values between 0 and 1, testNextIntUniform1 prints the return
> value of RandomDataImpl.nextInt (as double and as int). We see that -2
> through 5 are returned several times. The -3 value however, is only returned
> for 0.0, and is thus under-respresented in the integer samples. The output of
> test method testNextIntUniform2 also clearly shows that value -3 is never
> sampled.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira