7051516: ThreadLocalRandom seed is never initialized so all instances generate the same sequence
authordl
Mon, 20 Jun 2011 12:27:20 +0100
changeset 10056 7464dc04ae22
parent 10055 f5220ab72a1d
child 10057 03ae05289550
7051516: ThreadLocalRandom seed is never initialized so all instances generate the same sequence Reviewed-by: chegar, dholmes, mduigou
jdk/src/share/classes/java/util/Random.java
--- a/jdk/src/share/classes/java/util/Random.java	Mon Jun 20 17:38:15 2011 +0800
+++ b/jdk/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) {