public final class RandomTools extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CAPITAL_LETTERS
大写字母
|
static String |
LOWERCASE_LETTERS
小写字母
|
static String |
NUMBERS
数字
|
| Modifier and Type | Method and Description |
|---|---|
static ThreadLocalRandom |
currentThreadLocalRandom()
当前线程的
ThreadLocalRandom |
static SecureRandom |
defaultSecureRandom()
默认的
SecureRandom |
static int |
randomInt(int startInclusive,
int endExclusive)
使用当前线程的
ThreadLocalRandom,生成随机整数 |
static int |
randomInt(Random random,
int startInclusive,
int endExclusive)
使用传入的随机数生成器,生成随机整数
|
static int |
randomInt(Random random,
com.google.common.collect.Range<Integer> range)
使用传入的随机数生成器,生成随机整数
|
static int |
randomInt(com.google.common.collect.Range<Integer> range)
使用当前线程的
ThreadLocalRandom,生成随机整数 |
static String |
randomStr(char[] sourceCharacters,
int length)
使用当前线程的
ThreadLocalRandom,生成指定长度的字符串 |
static String |
randomStr(Random random,
char[] sourceCharacters,
int length)
使用传入的随机数生成器,生成指定长度的字符串
|
static String |
randomStr(Random random,
String sourceCharacters,
int length)
使用传入的随机数生成器,生成指定长度的字符串
|
static String |
randomStr(String sourceCharacters,
int length)
使用当前线程的
ThreadLocalRandom,生成指定长度的字符串 |
static int |
secureRandomInt(int startInclusive,
int endExclusive)
使用默认的
SecureRandom,生成随机整数 |
static int |
secureRandomInt(com.google.common.collect.Range<Integer> range)
使用默认的
SecureRandom,生成随机整数 |
static String |
secureRandomStr(char[] sourceCharacters,
int length)
使用默认的
SecureRandom,生成指定长度的字符串 |
static String |
secureRandomStr(String sourceCharacters,
int length)
使用默认的
SecureRandom,生成指定长度的字符串 |
public static final String CAPITAL_LETTERS
public static final String LOWERCASE_LETTERS
public static final String NUMBERS
public static SecureRandom defaultSecureRandom()
SecureRandomSecureRandompublic static ThreadLocalRandom currentThreadLocalRandom()
ThreadLocalRandomThreadLocalRandompublic static String randomStr(Random random, char[] sourceCharacters, int length)
random - 随机数生成器。根据需要可以传入
ThreadLocalRandom、SecureRandom
等,不为空sourceCharacters - 字符池。字符串的字符将在数组中选,不为空length - 字符串长度public static String randomStr(char[] sourceCharacters, int length)
ThreadLocalRandom,生成指定长度的字符串sourceCharacters - 字符池。字符串的字符将在数组中选,不为空length - 字符串长度public static String secureRandomStr(char[] sourceCharacters, int length)
SecureRandom,生成指定长度的字符串sourceCharacters - 字符池。字符串的字符将在数组中选,不为空length - 字符串长度public static String randomStr(Random random, String sourceCharacters, int length)
random - 随机数生成器。根据需要可以传入
ThreadLocalRandom、SecureRandom
等,不为空sourceCharacters - 字符池。字符串的字符将在数组中选,不为空length - 字符串长度public static String randomStr(String sourceCharacters, int length)
ThreadLocalRandom,生成指定长度的字符串sourceCharacters - 字符池。字符串的字符将在数组中选,不为空length - 字符串长度public static String secureRandomStr(String sourceCharacters, int length)
SecureRandom,生成指定长度的字符串sourceCharacters - 字符池。字符串的字符将在数组中选,不为空length - 字符串长度public static int randomInt(Random random, int startInclusive, int endExclusive)
startInclusive - 最小值(包含)endExclusive - 最大值(不包含)[min, max) 内的随机整数public static int randomInt(int startInclusive,
int endExclusive)
ThreadLocalRandom,生成随机整数startInclusive - 最小值(包含)endExclusive - 最大值(不包含)[min, max) 内的随机整数public static int secureRandomInt(int startInclusive,
int endExclusive)
SecureRandom,生成随机整数startInclusive - 最小值(包含)endExclusive - 最大值(不包含)[min, max) 内的随机整数public static int randomInt(Random random, com.google.common.collect.Range<Integer> range)
range - 整数区间public static int randomInt(com.google.common.collect.Range<Integer> range)
ThreadLocalRandom,生成随机整数range - 整数区间public static int secureRandomInt(com.google.common.collect.Range<Integer> range)
SecureRandom,生成随机整数range - 整数区间Copyright © 2026. All rights reserved.