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
41
package cn.wisenergy.common.utils;
import java.util.Random;
/**
* 生成充值卡子卡秘钥工具类
* @author 86187
*/
public class SecretkeyUtil {
//字符串长度
static final int LENGTH= 16;
//开头数字最小长度
static final int MIN_LENGTH_OF_NUMBER= 4;
//字母拼接最大位置
static final int MAX_LENGTH_OF_STRING=11;
public static String getSecretkey(){
char[] chars={'a','b','c','d','e','f','g','h','l','j','k','i','m','n','o','p','q','r','s','t','y','u','w','x','v','z'};
StringBuilder stringBuilder=new StringBuilder(16);
Random random = new Random();
int i1 =random.nextInt(4)+MIN_LENGTH_OF_NUMBER;
for (int i = 0; i <i1; i++) {
stringBuilder.append(random.nextInt(9));
}
while (i1<MAX_LENGTH_OF_STRING) {
int i2 =random.nextInt(25);
if (i2 < 26) {
stringBuilder.append(chars[i2]);
i1++;
}
}
for (int i = MAX_LENGTH_OF_STRING; i <LENGTH ; i++) {
stringBuilder.append(random.nextInt(9));
}
return stringBuilder.toString();
}
}