public static String getGUID() {
StringBuilder uid = new StringBuilder();
//产生16位的强随机数
Random rd = new SecureRandom();
for (int i = 0; i < 16; i++) {
//产生0-2的3位随机数
int type = rd.nextInt(3);
switch (type){
case 0:
//0-9的随机数
uid.append(rd.nextInt(10));
break;
case 1:
//ASCII在65-90之间为大写,获取大写随机
uid.append((char)(rd.nextInt(25)+65));
break;
case 2:
//ASCII在97-122之间为小写,获取小写随机
uid.append((char)(rd.nextInt(25)+97));
break;
default:
break;
}
}
return uid.toString();
}
//16位纯数字随机数
public static String getGUIDNUM() {
StringBuilder uid = new StringBuilder();
/*Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("hhmmss");
uid.append(sdf.format(date));
int lenght = uid.length();*/
int lenght = 0 ;
Random rd = new SecureRandom();
if(lenght<16){
for(int i=0;i<16-lenght;i++){
uid.append(rd.nextInt(10));
}
}
return uid.toString();
}
最后
以上就是哭泣水池最近收集整理的关于产生16位的强随机数的全部内容,更多相关产生16位内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复