You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dennis Hendriks (Issue Comment Edited) (JIRA)" <ji...@apache.org> on 2011/12/15 09:26:30 UTC

[jira] [Issue Comment Edited] (MATH-724) RandomDataImpl.nextInt does not distribute uniformly for negative lower bound

    [ https://issues.apache.org/jira/browse/MATH-724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13170025#comment-13170025 ] 

Dennis Hendriks edited comment on MATH-724 at 12/15/11 8:24 AM:
----------------------------------------------------------------

bq. Double.Min_VALUE is a positive number.

Oops...

OK, I uploaded a third version of the patch (math-724-v3.patch), which also applies the new formula for nextUniform. I included two test files (NextUniformTest3.java and NextIntTest3.java), that show the results for nextInt and nextUniform, for both the old and new formulas. As for as I can see, the new formula works equally well or better in all cases. Also, all existing unit tests pass.

                
      was (Author: dhendriks):
    bq. Double.Min_VALUE is a positive number.

Oops...

OK, I uploaded a third version of the patch, which also applies the new formula for nextUniform. I included two test files, that show the results for the old and new formulas. As for as I can see, the new formula works equally well or better in all cases. All existing unit tests pass.

                  
> 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: NextIntTest3.java, NextIntUniformTest.java, NextUniformTest3.java, math-724-v2.patch, math-724-v3.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