[
https://issues.apache.org/jira/browse/LANG-472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12829634#action_12829634
]
Sebb commented on LANG-472:
---------------------------
Just realised that nextInt() will never return Integer.MAX_VALUE.
Should it?
If so, then maybe the way to do this is:
{code}
int random=SHARED_RANDOM.nextInt();
if (random == Integer.MIN_VALUE) {
random = 0; // should solve problem of reduced frequency of 0
} else {
random = - random;
}
{code}
Could use the same approach for nextLong()
Thoughts?
> RandomUtils.nextLong() get all even number
> ------------------------------------------
>
> Key: LANG-472
> URL: https://issues.apache.org/jira/browse/LANG-472
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.math.*
> Environment: all system
> Reporter: zhangruimin
> Fix For: 2.x
>
> Attachments: LANG-472-alt.patch, lang-472.patch
>
>
> when we use the following code , we can see that the method produce only even
> number.
> while (true) {
> // for (int i = 0; i < 100; i++) {
> if (RandomUtils.nextLong() % 2 == 1) {
> System.out.println("ok");
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.