Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.sog.kit.encry;
 
 
 import java.util.UUID;

.

Author(s):
sagyf yang
Version:
1.0 2014-01-04 13:41
Since:
JDK 1.6
public class IdentitieKit {
    private static SecureRandom random = new SecureRandom();

    
封装JDK自带的UUID, 通过Random数字生成, 中间有-分割.
    public static String uuid() {
        return UUID.randomUUID().toString();
    }

    
封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
    public static String uuid2() {
        return UUID.randomUUID().toString().replaceAll(."");
    }

    
使用SecureRandom随机生成Long.
    public static long randomLong() {
        return Math.abs(.nextLong());
    }

    
基于Base62编码的SecureRandom随机生成bytes.
    public static String randomBase62(int length) {
        byte[] randomBytes = new byte[length];
        .nextBytes(randomBytes);
        return EncodeKit.encodeBase62(randomBytes);
    }
New to GrepCode? Check out our FAQ X