Java生成随机10位不重复邀请码
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
System.out.println(createShareCode());
}
}
private static String createShareCode() {
int maxNum = 36;
int i;
int count = 0;
char[] str = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
StringBuffer code = new StringBuffer("");
Random r = new Random();
while (count < 10) {
i = Math.abs(r.nextInt(maxNum));
if (i >= 0 && i < str.length) {
code.append(str[i]);
count++;
}
}
return code.toString();
}