chenjiahe
2023-05-31 7f9b53d982c0210ffc25db3a639bd858fc5db79b
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
42
43
44
45
46
package com.hx.util;
 
import java.util.Random;
 
public class CreateNoTool {
 
    /**获取随机秘钥(数字与大写字母组合)
     *
     * @param y
     *            随机数位数
     * @return
     */
    public static String randomKey(Integer y) {
        String[] data = new String[] {
                "0","1","2","3","4","5","6","7","8","9"
                ,"A","B","C","D","E","F","G","H","I","J"
                ,"K","L","M","N","O","P","Q","R","S","T"
                ,"U","V","W","S","Y","Z"
        };
        String no = "";
        Random r = new Random();
        for (int i = 0; i < y; i++) {
            no += data[r.nextInt(data.length-1)];
        }
        return no;
    }
 
    /**获取随机秘钥(数字)
     *
     * @param y
     *            随机数位数
     * @return
     */
    public static String randomKeyNumber(Integer y) {
        String[] data = new String[] {
                "0","1","2","3","4","5","6","7","8","9"
        };
        String no = "";
        Random r = new Random();
        for (int i = 0; i < y; i++) {
            no += data[r.nextInt(data.length-1)];
        }
        return no;
    }
 
}