Hello.

Le jeu. 12 févr. 2026 à 13:54, Jherek Healy
<[email protected]> a écrit :
>
> Dear Commons RNG Team,
>
> I am proposing to introduce a new method in IntProvider and 
> UniformRandomProvider which computes a random double number in the open 
> interval (0, 1).
>
> Right now, nextDouble() computes a random double in the semi-closed interval 
> [0,1). This can be problematic when the random number is to be used in a 
> inverse distribution function, to provide random numbers according to a 
> specific distribution, as the inverse distribution function is only defined 
> on the open interval.

Is this the sole use-case?
If so, wouldn't it be better (design-wise) to implement the functionality
in the "o.a.c.rng.sampling.distribution" package?

Regards,
Gilles

[1] 
https://commons.apache.org/proper/commons-rng/commons-rng-sampling/index.html

> The idea is to match the implementation of 
> https://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/VERSIONS/C-LANG/mt19937-64.cgenrand64_real3
>
> double genrand64_real3(void)
> {
>     return ((genrand64_int64() >> 12) + 0.5) * (1.0/4503599627370496.0);
> }
>
> There are two possible Java implementations:
> ((nextLong() >>> 12) + 0.5) * 0x1.0p-52;
> or equivalently (reusing the constant used for the semi-closed interval)
> ((v >>> 11) | 1) * * 0x1.0p-53;
>
> Yet another alternvative (which produces different numbers (last digit)) is 
> the union trick:
> long bits = (random64 >>> 12) | 0x3FF0000000000001L;
> return Double.longBitsToDouble(bits) - 1.0;
>
> I don't have a strong preference in either of the choices.
>
> Jherek

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to