MCPcopy Create free account
hub / github.com/SeanDragon/protools / ToolRandoms

Class ToolRandoms

common/src/main/java/pro/tools/data/text/ToolRandoms.java:12–207  ·  view source on GitHub ↗

随机数类 @author SeanDragon

Source from the content-addressed store, hash-verified

10 * @author SeanDragon
11 */
12public final class ToolRandoms {
13 private ToolRandoms() {
14 throw new UnsupportedOperationException("我是工具类,别初始化我。。。");
15 }
16
17 /**
18 * 定义验证码字符.去除了O、I、l、、等容易混淆的字母
19 */
20 private static final char[] AUTH_CODE_ALL = {
21 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
22 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
23 '3', '4', '5', '7', '8'};
24
25 /**
26 * 定义验证码数字
27 */
28 private static final char[] AUTH_CODE_NUMBER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
29
30 private static final int AUTH_CODE_ALL_LENGTH = AUTH_CODE_ALL.length;
31 private static final int AUTH_CODE_NUMBER_LENGTH = AUTH_CODE_NUMBER.length;
32 private static final SecureRandom RANDOM = new SecureRandom();
33
34 private final static char[] DIGITS = { //32位
35 '0', '1', '2', '3', '4', '5',
36 '6', '7', '8', '9', 'a', 'b',
37 'c', 'd', 'e', 'f', 'g', 'h',
38 'i', 'j', 'k', 'l', 'm', 'n',
39 'o', 'p', 'q', 'r', 's', 't',
40 'u', 'v', 'w', 'x', 'y', 'z'
41 }, digits_$ = {//64位
42 '0', '1', '2', '3', '4', '5',
43 '6', '7', '8', '9', 'a', 'b',
44 'c', 'd', 'e', 'f', 'g', 'h',
45 'i', 'j', 'k', 'l', 'm', 'n',
46 'o', 'p', 'q', 'r', 's', 't',
47 'u', 'v', 'w', 'x', 'y', 'z',
48 'A', 'B', 'C', 'D', 'E', 'F',
49 'G', 'H', 'I', 'J', 'K', 'L',
50 'M', 'N', 'O', 'P', 'Q', 'R',
51 'S', 'T', 'U', 'V', 'W', 'X',
52 'Y', 'Z', '_', '_'
53 };
54
55 /**
56 * 生成验证码
57 */
58 public static char getAuthCodeAllChar() {
59 return AUTH_CODE_ALL[getNumberRandom(0, AUTH_CODE_ALL_LENGTH)];
60 }
61
62 /**
63 * 生成验证码,纯数字
64 */
65 public static String getAuthCodeNumber(int length) {
66 StringBuilder sb = new StringBuilder();
67 for (int i = 0; i < length; i++) {
68 sb.append(AUTH_CODE_NUMBER[getNumberRandom(0, AUTH_CODE_NUMBER_LENGTH)]);
69 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected