RFR 8024253: ThreadLocal random can use SecureRandom for the initial seed
Paul Sandoz
paul.sandoz at oracle.com
Thu Oct 3 10:48:57 UTC 2013
[Catching up after J1]
On Sep 24, 2013, at 9:16 AM, Martin Buchholz <martinrb at google.com> wrote:
> Stupid SplittableRandom tricks:
>
> System.out.println(sr.nextDouble(0.0d,
> Double.POSITIVE_INFINITY));
> always prints constant 1.7976931348623157E308
>
> which might be considered a bug.
>
Right, Double.MAX_VALUE.
We thought not worth the effort of exhaustively supporting all possible IllegalArgumentException cases:
nextDouble(+oo) => Double.MAX_VALUE
nextDouble(-oo, finite) => NaN
nextDouble(-oo, +oo) => NaN
nextDouble(finite, +oo) => Double.MAX_VALUE
> ---
>
> The spec below fails to be pedantically correct when one of the args is NaN.
>
> * @throws IllegalArgumentException if {@code origin} is greater than
> * or equal to {@code bound}
> */
> public double nextDouble(double origin, double bound) {
>
> Better to draw inspiration from the spec for
> * @throws IllegalArgumentException if {@code bound} is not positive
> */
> public double nextDouble(double bound) {
>
> and write:
>
> * @throws IllegalArgumentException if {@code bound - origin} is not
> positive
> */
> public double nextDouble(double origin, double bound) {
>
That would be a good change to tack on to that for the better reporting of incorrect bounds.
Paul.
More information about the core-libs-dev
mailing list