项目中用到一授权码,网上搜索资源整理后发表
public class Random {
/**
* 生成32位大小写加数字随机数
* @param args
*/
public static void main(String[] args) {
String val = "";
java.util.Random random = new java.util.Random();
for (int i = 0; i < 32; i++) {//定义随机数位数
// 输出字母还是数字
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
// 字符串
if ("char".equalsIgnoreCase(charOrNum)) {
// 取得大写字母还是小写字母
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
val += (char) (choice + random.nextInt(26));
} else if ("num".equalsIgnoreCase(charOrNum)) { // 数字
val += String.valueOf(random.nextInt(10));
}
}
System.out.println("-----" + val);
}
}