java在泛型类中生成随机数
我想在泛型类中生成随机id号。 用户应该能够从大多数实现中进行选择。 在从长到字节的转换中,我的方法安全吗? 我不知道这样的沮丧会发生什么。结果会是多少? 它能找到均匀分布的数字吗
@SuppressWarnings("unchecked")
public class Test<I extends Number>
{
SecureRandom random = new SecureRandom();
I id = (I) random.nextLong();
while(Test.has(id))
{
id = (I) random.nextLong();
}
}
共 (0) 个答案