派生自 projectDept/qhighschool

胡仁荣
2023-08-04 2174b22bbbb45284765a23b8189df59583c65d29
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.qxueyou.scc.base.util;
 
import java.util.Random;
import java.util.UUID;
 
/**
 * UUID工具类
 * @author 德虎
 *
 */
public final class UUIDUtils {
    
    public static String[] chars = 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", "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", "X", "Y", "Z" };
    
    public static String specifalChars = "0123456789abcdefghijklmnopqrstuvwxyz";  
    
    /**
     * 生成UUID
     * @return
     */
    public static String generateUUID(){
        return UUID.randomUUID().toString();
    }
    
    /**
     * 生成UUID
     * @return
     */
    public static String UUID(){
        return UUID.randomUUID().toString().replace("-", "");
    }
    
    public static void main(String[] args) {
        System.out.println(UUIDUtils.UUID());
    }
    
    /**
     * 生成8位随机码
     * @return
     */
    public static String generateShortUuid() {  
        StringBuffer shortBuffer = new StringBuffer();  
        String uuid = UUID.randomUUID().toString().replace("-", "");  
        for (int i = 0; i < 8; i++) {  
            String str = uuid.substring(i * 4, i * 4 + 4);  
            int x = Integer.parseInt(str, 16);  
            shortBuffer.append(chars[x % 0x3E]);  
        }  
        return shortBuffer.toString();  
      
    } 
    
    /**
     * 生成最少16位随机码
     * @return
     */
    public static String generateSpecialUuid(int length) {
        
        length = length < 16 ? 16 : length ;
        
        StringBuffer sb = new StringBuffer();  
        Random random = new Random();  
        for (int i = 0; i < length; i++) {  
            sb.append(specifalChars.charAt(random.nextInt(specifalChars.length())));  
        }  
        return sb.toString();  
    } 
    
    
    
}