-
Sub-task
-
Resolution: Delivered
-
P4
-
22
A new method, `equiDoubles()`, has been added to `java.util.random.RandomGenerator`.
`equiDoubles()` guarantees a uniform distribution, provided the underlying `nextLong(long)` method returns uniformly distributed values, that is as dense as possible. It returns a `DoubleStream` rather than individual `double`s because of slightly expensive initial computations. They are better absorbed as setup costs for the stream rather than being repeated for each new computed value.
The aim is to overcome some numerical limitations in the families of `doubles()` and `nextDouble()` methods. In these, an affine transform is applied to a uniformly distributed pseudo-random value in the half-open interval [0.0, 1.0) to obtain a pseudo-random value in the half-open interval [origin, bound). However, due to the nature of floating-point arithmetic, the affine transform ends up in a slightly distorted distribution, which is not necessarily uniform.
`equiDoubles()` guarantees a uniform distribution, provided the underlying `nextLong(long)` method returns uniformly distributed values, that is as dense as possible. It returns a `DoubleStream` rather than individual `double`s because of slightly expensive initial computations. They are better absorbed as setup costs for the stream rather than being repeated for each new computed value.
The aim is to overcome some numerical limitations in the families of `doubles()` and `nextDouble()` methods. In these, an affine transform is applied to a uniformly distributed pseudo-random value in the half-open interval [0.0, 1.0) to obtain a pseudo-random value in the half-open interval [origin, bound). However, due to the nature of floating-point arithmetic, the affine transform ends up in a slightly distorted distribution, which is not necessarily uniform.