add RandomUtil.randomStringWithoutStr

This commit is contained in:
Looly 2019-10-09 10:59:34 +08:00
parent 17efa74406
commit 8e5bbdf170
2 changed files with 80 additions and 73 deletions

View File

@ -13,6 +13,7 @@
* 【core】 增加DateUtil.parseCST方法issue#570@Github
* 【core】 增加defaultIfEmpty方法
* 【crypto】 修改bigIntToFixexLengthBytes为bigIntToFixedLengthBytespr#575@Github
* 【core】 RandomUtil增加randomStringWithoutStrpr#76@Gitee
### Bug修复
* 【all】 修复阶乘计算错误bugissue#I12XE4@Gitee

View File

@ -27,15 +27,20 @@ import cn.hutool.core.lang.WeightRandom.WeightObj;
* 随机工具类
*
* @author xiaoleilu
*
*/
public class RandomUtil {
/** 用于随机选的数字 */
/**
* 用于随机选的数字
*/
public static final String BASE_NUMBER = "0123456789";
/** 用于随机选的字符 */
/**
* 用于随机选的字符
*/
public static final String BASE_CHAR = "abcdefghijklmnopqrstuvwxyz";
/** 用于随机选的字符和数字 */
/**
* 用于随机选的字符和数字
*/
public static final String BASE_CHAR_NUMBER = BASE_CHAR + BASE_NUMBER;
/**
@ -83,9 +88,9 @@ public class RandomUtil {
*
* @param isSecure 是否为强随机数生成器 (RNG)
* @return {@link Random}
* @since 4.1.15
* @see #getSecureRandom()
* @see #getRandom()
* @since 4.1.15
*/
public static Random getRandom(boolean isSecure) {
return isSecure ? getSecureRandom() : getRandom();
@ -401,9 +406,6 @@ public class RandomUtil {
public static String randomStringWithoutStr(int length, String elemData) {
String baseStr = BASE_CHAR_NUMBER;
baseStr = StrUtil.removeAll(baseStr, elemData.toCharArray());
if(baseStr.equals("")){
return "";
}
return randomString(baseStr, length);
}
@ -425,6 +427,9 @@ public class RandomUtil {
* @return 随机字符串
*/
public static String randomString(String baseString, int length) {
if (StrUtil.isEmpty(baseString)) {
return StrUtil.EMPTY;
}
final StringBuilder sb = new StringBuilder(length);
if (length < 1) {
@ -505,6 +510,7 @@ public class RandomUtil {
}
// ------------------------------------------------------------------- UUID
/**
* @return 随机UUID
* @deprecated 请使用{@link IdUtil#randomUUID()}