使用SecureRandom
是否可以保证2 个连续调用不会返回相同的数字?
如果这是客户端 API 端的严格要求,那么代码中的以下循环是否多余?
Random random = SecureRandom.getInstance("SHA1PRNG");
long value1 = (long)(r.nextDouble() * LIMIT) + 1;
long value2 = (long)(r.nextDouble() * LIMIT);
while(value1 == value2) {
value2 = (long)(r.nextDouble() * LIMIT);
}