763 * <p>This method is properly synchronized to allow correct use by |
763 * <p>This method is properly synchronized to allow correct use by |
764 * more than one thread. However, if many threads need to generate |
764 * more than one thread. However, if many threads need to generate |
765 * pseudorandom numbers at a great rate, it may reduce contention |
765 * pseudorandom numbers at a great rate, it may reduce contention |
766 * for each thread to have its own pseudorandom-number generator. |
766 * for each thread to have its own pseudorandom-number generator. |
767 * |
767 * |
|
768 * @apiNote |
|
769 * As the largest {@code double} value less than {@code 1.0} |
|
770 * is {@code Math.nextDown(1.0)}, a value {@code x} in the closed range |
|
771 * {@code [x1,x2]} where {@code x1<=x2} may be defined by the statements |
|
772 * |
|
773 * <blockquote><pre>{@code |
|
774 * double f = Math.random()/Math.nextDown(1.0); |
|
775 * double x = x1*(1.0 - f) + x2*f; |
|
776 * }</pre></blockquote> |
|
777 * |
768 * @return a pseudorandom {@code double} greater than or equal |
778 * @return a pseudorandom {@code double} greater than or equal |
769 * to {@code 0.0} and less than {@code 1.0}. |
779 * to {@code 0.0} and less than {@code 1.0}. |
|
780 * @see #nextDown(double) |
770 * @see Random#nextDouble() |
781 * @see Random#nextDouble() |
771 */ |
782 */ |
772 public static double random() { |
783 public static double random() { |
773 return RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble(); |
784 return RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble(); |
774 } |
785 } |