在实验三中涉及到了随机分配员工分配表,所以这里我去网络上搜索了关于随机数的相关原理进行实验。
1. Long型伪随机数
指定最大值的随机数:
public static Long getLongRd(int max){
return ThreadLocalRandom.current().nextLong(max);
}
Long型范围的随机数:2892122192609993272
public static Long getLongRd(){
return ThreadLocalRandom.current().nextLong(Long.MAX_VALUE);
}
十六进制表示的随机数:3c2cdc45ed09c661
public static String getHexLongRd(){
return Long.toHexString(getLongRd());
}
2. Int型伪随机数
Int型范围的随机数:157243445
public static int getIntRd(){
return ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE);
}
十六进制表示的随机数:4a6e8ad6
public static String getHexIntRd(){
return Integer.toHexString(getIntRd());
}
3.随机数的原理:
生成范围值:
方法1.以生成[10,20]随机数为例,首先生成0-20的随机数,然后对(20-10+1)取模得到[0-10]之间的随机数,然后加上min=10,最后生成的是10-20的随机数
方法2.生成[1,,10]随机数,random。nextInt(9)+1
正态分布
double nextGaussian