chenjiahe
2023-01-10 bcc2fa8323a61920c7d2a6139c38fc25b17baa7f
提交 | 用户 | age
5c5945 1 package com.hx.util;
E 2
3 import java.util.Random;
4
5 public class CreateNoTool {
6
7     /**获取随机秘钥(数字与大写字母组合)
8      *
9      * @param y
10      *            随机数位数
11      * @return
12      */
13     public static String randomKey(Integer y) {
14         String[] data = new String[] {
15                 "0","1","2","3","4","5","6","7","8","9"
16                 ,"A","B","C","D","E","F","G","H","I","J"
17                 ,"K","L","M","N","O","P","Q","R","S","T"
18                 ,"U","V","W","S","Y","Z"
19         };
20         String no = "";
21         Random r = new Random();
22         for (int i = 0; i < y; i++) {
23             no += data[r.nextInt(data.length-1)];
24         }
25         return no;
26     }
27
28     /**获取随机秘钥(数字)
29      *
30      * @param y
31      *            随机数位数
32      * @return
33      */
34     public static String randomKeyNumber(Integer y) {
35         String[] data = new String[] {
36                 "0","1","2","3","4","5","6","7","8","9"
37         };
38         String no = "";
39         Random r = new Random();
40         for (int i = 0; i < y; i++) {
41             no += data[r.nextInt(data.length-1)];
42         }
43         return no;
44     }
45
46 }