changeset 4567:791e94e7b64f

7051516: ThreadLocalRandom seed is never initialized so all instances generate the same sequence Reviewed-by: chegar, dholmes, mduigou
author chegar
date Thu, 01 Sep 2011 13:05:08 +0100
parents 85d7fc20baa5
children 1c0190388b70
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	Thu Sep 01 00:09:34 2011 +0100
+++ b/src/share/classes/java/util/Random.java	Thu Sep 01 13:05:08 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) {