项目场景:
最近项目生成id懒得用Twitter那个雪花法了,寻思着弄时间戳随机字符串算了
发现个挺好的用的类
org.apache.commons.lang.RandomStringUtils;
public static String random(int count, boolean letters, boolean numbers) {
return random(count, 0, 0, letters, numbers);
}
public static String random(int count, int start, int end, boolean letters, boolean numbers) {
return random(count, start, end, letters, numbers, (char[])null, RANDOM);
}
public static String random(int count, int start, int end, boolean letters, boolean numbers, char[] chars) {
return random(count, start, end, letters, numbers, chars, RANDOM);
}
里面有多种参数供你配置,生成想要的字符串
解决方案:
例子:
String randStr = RandomStringUtils.random(7, true, true);