【发布时间】:2017-02-11 11:54:45
【问题描述】:
是否可以向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,或者它不是为此而设计的吗?
【问题讨论】:
-
当公共规范已经给你答案时,为什么还要看实现呢?
Like the global {@link java.util.Random} generator used by the {@link java.lang.Math} class, a {@code ThreadLocalRandom} is initialized with an internally generated seed that may not otherwise be modified. -
是的,你是对的。应该更仔细地阅读它。
标签: java random random-seed