commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dennis Hendriks (Updated) (JIRA)" <>
Subject [jira] [Updated] (MATH-724) RandomDataImpl.nextInt does not distribute uniformly for negative lower bound
Date Tue, 13 Dec 2011 08:23:30 GMT


Dennis Hendriks updated MATH-724:

    Attachment: math-724.patch

math-724.patch: it first scales the [0..1) interval to [0..length), then discretizes it, and
finally shifts it to [lower, upper].

It may be a good idea to also add some tests for cases such as [0,3], [3,5], [-3,5], [-5,
-3], and see if the distribution of sampled values is uniform. It seems RandomDataTest.testNextInt
does this using chiSquare, but since I'm not familiar with that, I'm not sure how to add more
tests for the other lower/upper bound pairs...
> RandomDataImpl.nextInt does not distribute uniformly for negative lower bound
> -----------------------------------------------------------------------------
>                 Key: MATH-724
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: Nightly Builds
>            Reporter: Dennis Hendriks
>         Attachments:, 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 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:!default.jspa
For more information on JIRA, see:


View raw message