[ https://issues.apache.org/jira/browse/LANG-472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12829827#action_12829827 ]
Sebb commented on LANG-472: --------------------------- Math.abs() can return a negative number if parameter is MIN_VALUE. Replacing this with 0 makes it non-negative and solves problem of reduced frequency of zero. Applied to nextInt() and nextLong(): URL: http://svn.apache.org/viewvc?rev=906693&view=rev Log: Math.abs(long) can return a negative number Fix nextInt() and nextLong() so all values 0 -> MAX_VALUE are equally likely I think the only remaining problem is the method nextLong(long) does not generate properly distributed numbers above about Long.MAX_VALUE/1000, possibly lower. > 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.