changeset 4358:411d02c13385

7051516: ThreadLocalRandom seed is never initialized so all instances generate the same sequence Reviewed-by: chegar, dholmes, mduigou
author dl
date Mon, 20 Jun 2011 12:27:20 +0100
parents 82706552f7a3
children a015dda3bdc6
files src/share/classes/java/util/Random.java
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Random.java	Mon Jun 20 17:38:15 2011 +0800
+++ b/src/share/classes/java/util/Random.java	Mon Jun 20 12:27:20 2011 +0100
@@ -118,7 +118,13 @@
      * @see   #setSeed(long)
      */
     public Random(long seed) {
-        this.seed = new AtomicLong(initialScramble(seed));
+        if (getClass() == Random.class)
+            this.seed = new AtomicLong(initialScramble(seed));
+        else {
+            // subclass might have overriden setSeed
+            this.seed = new AtomicLong();
+            setSeed(seed);
+        }
     }
 
     private static long initialScramble(long seed) {