RFR: 8302987: Add uniform and spatially equidistributed bounded double streams to RandomGenerator [v10]
Joe Darcy
darcy at openjdk.org
Tue Jul 18 02:57:53 UTC 2023
On Wed, 31 May 2023 11:57:19 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> The `default` method `nextDouble(double origin, double bound)` in `java.util.random.RandomGenerator` aims at generating a uniformly and spatially equidistributed random `double` in the left-closed and right-open range [`origin`, `bound`). It does so by applying the affine transform `origin + (bound - origin) * r` to a uniformly and spatially equidistributed random `double` `r` in the range [0, 1).
>>
>> Since floating-point arithmetic suffers from small but noticeable rounding errors, this ends up slightly deforming the distribution of `r` when applying the affine transform.
>
> Raffaello Giulietti has updated the pull request incrementally with one additional commit since the last revision:
>
> Correction in comment.
I read over the cited paper and the code in the PR.
If this new method is sufficiently used, we could considering adding and equidoubles(double a, b) overload for the [a, b) case.
src/java.base/share/classes/java/util/random/RandomGenerator.java line 398:
> 396: * afforded by nextLong().
> 397: */
> 398: delta = nextUp(left) - left;
The delta computations are equivalent to some expression phrased in terms of an ulp (Math.ulp) of a the endpoint or a value adjacent to the endpoint. If the ulp method is not used for the computation, I suggest adding a comment noting the equivalence.
-------------
Marked as reviewed by darcy (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/12719#pullrequestreview-1534025771
PR Review Comment: https://git.openjdk.org/jdk/pull/12719#discussion_r1266129903
More information about the core-libs-dev
mailing list