mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-29 01:47:07 +08:00
修复RandomUtil.randomStringWithoutStr方法问题
This commit is contained in:
parent
3fc15c4f24
commit
ce6c2ae15b
@ -675,14 +675,28 @@ public class RandomUtil {
|
||||
return randomString(BASE_CHAR_NUMBER_LOWER, length).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得一个随机的字符串(只包含数字和字母) 并排除指定字符串
|
||||
*
|
||||
* @param length 字符串的长度
|
||||
* @param elemData 要排除的字符串,如:去重容易混淆的字符串,oO0、lL1、q9Q、pP,区分大小写
|
||||
* @return 随机字符串
|
||||
*/
|
||||
public static String randomStringWithoutStr(final int length, final String elemData) {
|
||||
String baseStr = BASE_CHAR_NUMBER;
|
||||
baseStr = StrUtil.removeAll(baseStr, elemData.toCharArray());
|
||||
return randomString(baseStr, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得一个随机的字符串(只包含数字和小写字母) 并排除指定字符串
|
||||
*
|
||||
* @param length 字符串的长度
|
||||
* @param elemData 要排除的字符串,如:去重容易混淆的字符串,oO0、lL1、q9Q、pP,不区分大小写
|
||||
* @return 随机字符串
|
||||
* @since 5.8.28
|
||||
*/
|
||||
public static String randomStringWithoutStr(final int length, final String elemData) {
|
||||
public static String randomStringLowerWithoutStr(final int length, final String elemData) {
|
||||
String baseStr = BASE_CHAR_NUMBER_LOWER;
|
||||
baseStr = StrUtil.removeAll(baseStr, elemData.toLowerCase().toCharArray());
|
||||
return randomString(baseStr, length);
|
||||
|
@ -76,11 +76,9 @@ public class RandomUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void randomStringWithoutStrTest() {
|
||||
public void randomStringLowerWithoutStrTest() {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
final String s = RandomUtil.randomStringWithoutStr(8, "0IPOL");
|
||||
System.out.println(s);
|
||||
final String s = RandomUtil.randomStringLowerWithoutStr(8, "0IPOL");
|
||||
for (final char c : "0IPOL".toCharArray()) {
|
||||
Assertions.assertFalse(s.contains((String.valueOf(c).toLowerCase(Locale.ROOT))));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user