提交 | 用户 | age
|
11f947
|
1 |
package com.hx.util.code; |
C |
2 |
|
|
3 |
import com.hx.util.DateUtil; |
|
4 |
import com.hx.util.StringUtils; |
|
5 |
import org.apache.commons.lang3.RandomStringUtils; |
|
6 |
|
|
7 |
import java.util.Date; |
|
8 |
import java.util.Random; |
|
9 |
|
|
10 |
/**生成编号工具 |
|
11 |
*/ |
|
12 |
public class NumberTool { |
|
13 |
|
|
14 |
/**大小写字母*/ |
|
15 |
private static final String LETTER_ARR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
|
16 |
/**大小写字母和数字*/ |
|
17 |
private static final String LETTER_NUMBER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
|
18 |
/**小写字母*/ |
|
19 |
private static final String LETTER_SMALL = "abcdefghijklmnopqrstuvwxyz"; |
|
20 |
/**大写字母*/ |
|
21 |
private static final String LETTER_BIG = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
22 |
|
|
23 |
|
|
24 |
/**随机获大写字母组合 |
|
25 |
* @param lengrhCount 长度 |
|
26 |
* @return |
|
27 |
*/ |
|
28 |
public static String letterBig(long lengrhCount){ |
|
29 |
char[] c = LETTER_BIG.toCharArray(); |
|
30 |
Random random = new Random(); |
|
31 |
|
|
32 |
StringBuilder data = new StringBuilder(); |
|
33 |
for( int i = 0; i < lengrhCount; i ++) { |
|
34 |
data.append(c[random.nextInt(c.length)]); |
|
35 |
} |
|
36 |
return data.toString(); |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
/**随机获小写字母组合 |
|
41 |
* @param lengrhCount 长度 |
|
42 |
* @return |
|
43 |
*/ |
|
44 |
public static String letterSmall(long lengrhCount){ |
|
45 |
char[] c = LETTER_SMALL.toCharArray(); |
|
46 |
Random random = new Random(); |
|
47 |
|
|
48 |
StringBuilder data = new StringBuilder(); |
|
49 |
for( int i = 0; i < lengrhCount; i ++) { |
|
50 |
data.append(c[random.nextInt(c.length)]); |
|
51 |
} |
|
52 |
return data.toString(); |
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
/**随机获取大小写字母和数字组合 |
|
57 |
* @param lengrhCount 长度 |
|
58 |
* @return |
|
59 |
*/ |
|
60 |
public static String letterNumber(long lengrhCount){ |
|
61 |
char[] c = LETTER_NUMBER.toCharArray(); |
|
62 |
Random random = new Random(); |
|
63 |
|
|
64 |
StringBuilder data = new StringBuilder(); |
|
65 |
for( int i = 0; i < lengrhCount; i ++) { |
|
66 |
data.append(c[random.nextInt(c.length)]); |
|
67 |
} |
|
68 |
return data.toString(); |
|
69 |
} |
|
70 |
|
|
71 |
/**随机获取大小写字母组合 |
|
72 |
* @param lengrhCount 长度 |
|
73 |
* @return |
|
74 |
*/ |
|
75 |
public static String letterRandom(long lengrhCount){ |
|
76 |
char[] c = LETTER_ARR.toCharArray(); |
|
77 |
Random random = new Random(); |
|
78 |
|
|
79 |
StringBuilder data = new StringBuilder(); |
|
80 |
for( int i = 0; i < lengrhCount; i ++) { |
|
81 |
data.append(c[random.nextInt(c.length)]); |
|
82 |
} |
|
83 |
return data.toString(); |
|
84 |
} |
|
85 |
|
|
86 |
/**随机生成字符串(0-9) |
|
87 |
* @param lengthCount 长度 |
|
88 |
* @return |
|
89 |
*/ |
|
90 |
public static String generateCardNo(long lengthCount) { |
|
91 |
Random r=new Random(); |
|
92 |
//定义变长字符串 |
|
93 |
StringBuilder str = new StringBuilder(); |
|
94 |
for(int i=0;i<lengthCount;i++){ |
|
95 |
str.append(r.nextInt(10)); |
|
96 |
} |
|
97 |
return str.toString(); |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
} |