是否可以为ThreadLocalRandom
提供种子?
/**
* 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
使用种子,或者它不是为此而设计的吗?
答案 0 :(得分:0)
正如@Marko Topolnik所说,ThreadLocalRandom
不允许设置您自己的种子。
您可以使用this question中讨论的ThreadLocal<Random>
来绕过此问题。