1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| package com.ruoyi.common.utils;
|
|
| import java.util.Random;
|
| public class RandomUtil {
| /**
| * 字符串池
| */
| private static String[] STR_ARR = new String[] { "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", "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", "1", "2", "3", "4", "5",
| "6", "7", "8", "9", "0" };
|
| /**
| *
| * 根据指定的长度生成的含有大小写字母及数字的字符串
| *
| * @param length
| * 指定的长度
| * @return 按照指定的长度生成的含有大小写字母及数字的字符串
| */
| public static String generateRandomString(int length) {
| StringBuilder sb = new StringBuilder();
| Random rand = new Random();
| for (int i = 0; i < length; i++) {
| sb.append(STR_ARR[rand.nextInt(STR_ARR.length)]);
| }
| return sb.toString();
| }
|
| public static void main(String[] args) {
| String s = generateRandomString(26);
| System.out.println(s);
|
| }
|
| }
|
|