nextDouble = ((double) nextLong() - -9.223372036854776E18) * 5.421010862427522E-20;
/** * Returns a 64 bit uniformly distributed random number in the open unit * interval <code>(0.0,1.0)</code> (excluding 0.0 and 1.0). */ public double nextDouble() { double nextDouble; do { // -9.223372036854776E18 == (double) Long.MIN_VALUE // 5.421010862427522E-20 == 1 / Math.pow(2,64) == 1 / ((double) // Long.MAX_VALUE - (double) Long.MIN_VALUE); nextDouble = ((double) nextLong() - -9.223372036854776E18) * 5.421010862427522E-20; } // catch loss of precision of long --> double conversion while (!(nextDouble > 0.0 && nextDouble < 1.0)); // --> in (0.0,1.0) return nextDouble; /* * nextLong == Long.MAX_VALUE --> 1.0 nextLong == Long.MIN_VALUE --> 0.0 * nextLong == Long.MAX_VALUE-1 --> 1.0 nextLong == * Long.MAX_VALUE-100000L --> 0.9999999999999946 nextLong == * Long.MIN_VALUE+1 --> 0.0 nextLong == Long.MIN_VALUE-100000L --> * 0.9999999999999946 nextLong == 1L --> 0.5 nextLong == -1L --> 0.5 * nextLong == 2L --> 0.5 nextLong == -2L --> 0.5 nextLong == 2L+100000L * --> 0.5000000000000054 nextLong == -2L-100000L --> * 0.49999999999999456 */ }
nextDouble = ((double) nextLong() - -9.223372036854776E18) * 5.421010862427522E-20;