On Mon, 28 Jun 2021 15:26:45 GMT, Roger Riggs <rri...@openjdk.org> wrote:

>> The wording of the @implSpec referred to internal methods in the 
>> description. The patch rewords the @implSpec to be more descriptive of the 
>> algorithm than the methods used.
>
> src/java.base/share/classes/java/util/random/RandomGenerator.java line 648:
> 
>> 646:      * power of two then limiting is a simple masking operation. 
>> Otherwise, a
>> 647:      * new result is re-calculated by averaging the previous result and
>> 648:      * {@code nextInt()} until the final result is greater equal zero 
>> and less
> 
> I don't see how 'averaging' comes from the invocation of boundedNextInt which 
> appears to choose the first candidate that meets the criteria.
> The comment also applies to nextLong overloads.

If the first value calculated doesn't meet the criteria, then you either mask 
(power of 2) or go into this loop with does the averaging. The intent is not to 
bias the outcome.


                for (long u = r >>> 1;            // ensure nonnegative
                     u + m - (r = u % n) < 0L;    // rejection check
                     u = rng.nextLong() >>> 1) // retry
                    ;

-------------

PR: https://git.openjdk.java.net/jdk17/pull/151

Reply via email to