ThreadLocalRandom setSeed

问题描述 投票:3回答:1

是否有可能为ThreadLocalRandom提供种子?

looks like it isn't

/**
 * Throws {@code UnsupportedOperationException}.  Setting seeds in
 * this generator is not supported.
 *
 * @throws UnsupportedOperationException always
 */
public void setSeed(long seed) {
    if (initialized)
        throw new UnsupportedOperationException();
    rnd = (seed ^ multiplier) & mask;
}

那么我们可以使用ThreadLocalRandom使用种子或它不是为此而设计的吗?

java random random-seed
1个回答
0
投票

正如@Marko Topolnik评论的那样,ThreadLocalRandom不允许设置自己的种子。您可以使用ThreadLocal<Random>绕过此问题,如this question中所述。

© www.soinside.com 2019 - 2024. All rights reserved.