提交 4969a1ad 编写于 作者: D dl

7051516: ThreadLocalRandom seed is never initialized so all instances generate the same sequence

Reviewed-by: chegar, dholmes, mduigou
上级 9c924c38
...@@ -118,7 +118,13 @@ class Random implements java.io.Serializable { ...@@ -118,7 +118,13 @@ class Random implements java.io.Serializable {
* @see #setSeed(long) * @see #setSeed(long)
*/ */
public Random(long seed) { 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) { private static long initialScramble(long seed) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册