网上找到几种随机数生成的方法但是不知道那种比较安全
1.SecureRandom
2.double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength);
第一种 实现网上的有点看不懂
萌新就问 =|=
网上找到几种随机数生成的方法但是不知道那种比较安全
1.SecureRandom
2.double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength);
第一种 实现网上的有点看不懂
萌新就问 =|=
package com.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class CreatRandom {
public static final String getRondow() {
String[] array = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
StringBuffer s = new StringBuffer();
Random random = new Random();
/*Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
String newdate = dateFormat.format(date);
s.append(newdate.substring(2, 4));//年
s.append(newdate.substring(5, 7));//月
s.append(newdate.substring(8,10));//日
*/ for (int i = 0; i < 4; i++) {//4位随机数
s.append(array[random.nextInt(4)]);
}
return s.toString();
}
public static void main(String[] args) {
System.out.println(getRondow());
}
}