MCPcopy Create free account
hub / github.com/Hello-hao/Tbed / RandomUtils

Class RandomUtils

src/main/java/cn/hellohao/utils/verifyCode/RandomUtils.java:6–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import java.util.Random;
5
6public class RandomUtils extends org.apache.commons.lang3.RandomUtils {
7
8private static final char[] CODE_SEQ = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
9'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
10'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' };
11
12private static final char[] NUMBER_ARRAY = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
13
14private static Random random = new Random();
15
16public static String randomString(int length) {
17StringBuilder sb = new StringBuilder();
18for (int i = 0; i < length; i++) {
19sb.append(String.valueOf(CODE_SEQ[random.nextInt(CODE_SEQ.length)]));
20}
21return sb.toString();
22}
23
24public static String randomNumberString(int length) {
25StringBuilder sb = new StringBuilder();
26for (int i = 0; i < length; i++) {
27sb.append(String.valueOf(NUMBER_ARRAY[random.nextInt(NUMBER_ARRAY.length)]));
28}
29return sb.toString();
30}
31
32public static Color randomColor(int fc, int bc) {
33int f = fc;
34int b = bc;
35Random random = new Random();
36if (f > 255) {
37f = 255;
38}
39if (b > 255) {
40b = 255;
41}
42return new Color(f + random.nextInt(b - f), f + random.nextInt(b - f), f + random.nextInt(b - f));
43}
44
45public static int nextInt(int bound) {
46return random.nextInt(bound);
47}
48}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected