On Wed, 22 Feb 2023 15:23:13 GMT, Raffaello Giulietti <rgiulie...@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.

The effect of rounding errors in the affine transform is analyzed in:
Goualard, "Drawing random floating-point numbers from an interval", ACM 
Transactions on Modeling and Computer Simulation, 2022, 32 (3) available [here] 
(https://hal.science/hal-03282794v4)

The code in this PR is inspired by that paper, although it proposes another 
implementation preserving uniformity and equidistribution.

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

PR: https://git.openjdk.org/jdk/pull/12719

Reply via email to