commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] Updated: (LANG-472) RandomUtils.nextLong() get all even number
Date Thu, 27 Nov 2008 17:26:44 GMT

     [ https://issues.apache.org/jira/browse/LANG-472?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Phil Steitz updated LANG-472:
-----------------------------

    Attachment: lang-472.patch

Looks like this is due to loss of significance in the multiply (per the comment ;)

Attached patch replaces the impl with the JDK-supplied method, maintaining the (undocumented)
non-negative behavior.  Added test confirms that returned values are evenly distributed mod
2. 

This problem also affects nextLong(n) where n is sufficiently large.  We should either replace
the implementation with something else that works for large values of n or determine and document
the upper bound.

> RandomUtils.nextLong() get all even number
> ------------------------------------------
>
>                 Key: LANG-472
>                 URL: https://issues.apache.org/jira/browse/LANG-472
>             Project: Commons Lang
>          Issue Type: Bug
>         Environment: all system
>            Reporter: zhangruimin
>         Attachments: 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.


Mime
View raw message