changeset 9708:d7d5e8c035b1

8035427: Math.random() JavaDoc: missing maximum returned value Summary: Add some documentation amplifying the description of Math.random(). Reviewed-by: psandoz
author bpb
date Fri, 11 Apr 2014 13:12:11 -0700
parents 15b75b2df725
children 9e7bd44ea85c
files src/share/classes/java/lang/Math.java
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/Math.java	Fri Apr 11 09:25:36 2014 +0100
+++ b/src/share/classes/java/lang/Math.java	Fri Apr 11 13:12:11 2014 -0700
@@ -765,8 +765,19 @@
      * pseudorandom numbers at a great rate, it may reduce contention
      * for each thread to have its own pseudorandom-number generator.
      *
+     * @apiNote
+     * As the largest {@code double} value less than {@code 1.0}
+     * is {@code Math.nextDown(1.0)}, a value {@code x} in the closed range
+     * {@code [x1,x2]} where {@code x1<=x2} may be defined by the statements
+     *
+     * <blockquote><pre>{@code
+     * double f = Math.random()/Math.nextDown(1.0);
+     * double x = x1*(1.0 - f) + x2*f;
+     * }</pre></blockquote>
+     *
      * @return  a pseudorandom {@code double} greater than or equal
      * to {@code 0.0} and less than {@code 1.0}.
+     * @see #nextDown(double)
      * @see Random#nextDouble()
      */
     public static double random() {