添加 IdGen.randomShortString() 方法

This commit is contained in:
thinkgem
2024-04-25 23:31:11 +08:00
parent aedd50c8c2
commit 9573da0309
3 changed files with 23 additions and 9 deletions

View File

@@ -27,13 +27,6 @@ public class IdGen {
public static String uuid() {
return StringUtils.replace(UUID.randomUUID().toString(),"-", "");
}
/**
* 使用SecureRandom随机生成Long.
*/
public static long randomLong() {
return Math.abs(random.nextLong());
}
/**
* 基于Base62编码的SecureRandom随机生成bytes.
@@ -44,12 +37,33 @@ public class IdGen {
return EncodeUtils.encodeBase62(randomBytes);
}
/**
* 随机小写字符串
*/
public static String randomString(int length) {
return randomBase62(length).toLowerCase();
}
/**
* 随机简短小写字符串(对重复频率要求不高的使用)
*/
public static String randomShortString() {
return randomBase62(4).toLowerCase();
}
/**
* 使用SecureRandom随机生成指定范围的Integer.
*/
public static int randomInt(int min, int max) {
return random.nextInt(max) % (max - min + 1) + min;
}
/**
* 使用SecureRandom随机生成Long.
*/
public static long randomLong() {
return Math.abs(random.nextLong());
}
/**
* 获取新唯一编号18为数值