序列只包含数字和大写字母,不包含小写字母
20位序列生成:自定义标识位(1位)+随机位(3位)+UUID序列(16位)
22位序列生成:自定义标识位(1位)+时间位(13位)+UUID序列(8位)
22位随机序列
public class KeyGreaterUtil {
public String greater(char flag){
Long time=System.currentTimeMillis();
String result=flag+String.valueOf(time)+getUuid();
return result;
}
public static String[] chars = 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", "X", "Y", "Z" };
public static String getUuid() {
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 % 36]);
}
return shortBuffer.toString();
}
}
20位随机序列
public class KeyGreaterUtil2 {
public String greater(char flag){
int ran=(int)(Math.random()*900)+100;
String result=flag+String.valueOf(ran)+getUuid();
return result;
}
public static String[] chars = 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", "X", "Y", "Z" };
public static String getUuid() {
StringBuffer shortBuffer = new StringBuffer();
String uuid = UUID.randomUUID().toString().replace("-", "");
for (int i = 0; i < 16; i++) {
String str = uuid.substring(i * 2, i * 2 + 2);
int x = Integer.parseInt(str, 16);
shortBuffer.append(chars[x % 36]);
}
return shortBuffer.toString();
}
}
参考地址:http://mengxiang-it.iteye.com/blog/2319492
作者github地址:https://github.com/cyc3552637