// 抛出运行时异常
if (len > n && isCanRepeat == false) {
throw new RuntimeException(String.format(
"调用SecurityCode.getSecurityCode(%1$s,%2$s,%3$s)出现异常,"
+ "当isCanRepeat为%3$s时,传入参数%1$s不能大于%4$s", len,
level, isCanRepeat, n));
}
// 存放抽取出来的字符
char[] result = new char[len];
// 判断能否出现重复的字符
if (isCanRepeat) {
for (int i = 0; i < result.length; i++) {
// 索引 0 and n-1
int r = (int) (Math.random() * n);
// 将result中的第i个元素设置为codes[r]存放的数值
result = codes[r];
}
} else {
for (int i = 0; i < result.length; i++) {
// 索引 0 and n-1
int r = (int) (Math.random() * n);