添加随机工具类。

feature/net-util
ZhouXY108 2023-07-18 15:29:07 +08:00
parent 7c37d364d4
commit 7208aa5aae
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package xyz.zhouxy.plusone.commons.util;
import java.security.SecureRandom;
public final class RandomUtil {
private RandomUtil() {
throw new IllegalStateException("Utility class");
}
public static String secureRandomStr(char[] sourceCharacters, int length) {
SecureRandom random = new SecureRandom();
char[] result = new char[length];
for (int i = 0; i < length; i++) {
result[i] = sourceCharacters[random.nextInt(sourceCharacters.length)];
}
return String.valueOf(result);
}
}