aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/java/lang/StrictMath.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/classes/java/lang/StrictMath.java')
-rw-r--r--src/share/classes/java/lang/StrictMath.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/share/classes/java/lang/StrictMath.java b/src/share/classes/java/lang/StrictMath.java
index f2f275b5c..916b82ff9 100644
--- a/src/share/classes/java/lang/StrictMath.java
+++ b/src/share/classes/java/lang/StrictMath.java
@@ -667,9 +667,9 @@ public final class StrictMath {
private static Random randomNumberGenerator;
- private static synchronized void initRNG() {
- if (randomNumberGenerator == null)
- randomNumberGenerator = new Random();
+ private static synchronized Random initRNG() {
+ Random rnd = randomNumberGenerator;
+ return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
}
/**
@@ -680,9 +680,11 @@ public final class StrictMath {
*
* <p>When this method is first called, it creates a single new
* pseudorandom-number generator, exactly as if by the expression
- * <blockquote>{@code new java.util.Random}</blockquote> This
- * new pseudorandom-number generator is used thereafter for all
- * calls to this method and is used nowhere else.
+ *
+ * <blockquote>{@code new java.util.Random()}</blockquote>
+ *
+ * This new pseudorandom-number generator is used thereafter for
+ * all calls to this method and is used nowhere else.
*
* <p>This method is properly synchronized to allow correct use by
* more than one thread. However, if many threads need to generate
@@ -691,11 +693,12 @@ public final class StrictMath {
*
* @return a pseudorandom {@code double} greater than or equal
* to {@code 0.0} and less than {@code 1.0}.
- * @see java.util.Random#nextDouble()
+ * @see Random#nextDouble()
*/
public static double random() {
- if (randomNumberGenerator == null) initRNG();
- return randomNumberGenerator.nextDouble();
+ Random rnd = randomNumberGenerator;
+ if (rnd == null) rnd = initRNG();
+ return rnd.nextDouble();
}
/**