是否有可能为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
使用种子或它不是为此而设计的吗?
正如@Marko Topolnik评论的那样,ThreadLocalRandom
不允许设置自己的种子。您可以使用ThreadLocal<Random>
绕过此问题,如this question中所述。