Random random = new Random();
char[] keys = new char[8];
for (int i = 0; i < keys.length; i++) {
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写还是小写
keys[i] = (char) (choice + random.nextInt(26));
}
System.out.println(keys);
转载于:https://my.oschina.net/oldfeel/blog/173322