public class RandomKit extends Object
| Constructor and Description |
|---|
RandomKit() |
| Modifier and Type | Method and Description |
|---|---|
static ThreadLocalRandom |
getRandom()
获取随机数生成器对象
ThreadLocalRandom是JDK 7之后提供并发产生随机数,能够解决多个线程发生的竞争争夺
|
static Random |
getRandom(boolean isSecure)
获取随机数产生器
|
static SecureRandom |
getSecureRandom()
获取
SecureRandom,类提供加密的强随机数生成器 (RNG) |
static SecureRandom |
getSecureRandom(byte[] seed)
创建
SecureRandom,类提供加密的强随机数生成器 (RNG) |
static BigDecimal |
randomBigDecimal()
获得指定范围内的随机数[0, 1)
|
static BigDecimal |
randomBigDecimal(BigDecimal limit)
获得指定范围内的随机数 [0,limit)
|
static BigDecimal |
randomBigDecimal(BigDecimal min,
BigDecimal max)
获得指定范围内的随机数
|
static boolean |
randomBoolean()
获得随机Boolean值
|
static byte[] |
randomBytes(int length)
随机bytes
|
static char |
randomChar()
随机字母或数字,小写
|
static char |
randomChar(String baseString)
随机字符
|
static Color |
randomColor()
生成随机颜色
|
static DateTime |
randomDate(Date baseDate,
Fields.DateField dateField,
int min,
int max)
以给定日期为基准,随机产生一个日期
|
static DateTime |
randomDay(int min,
int max)
以当天为基准,随机产生一个日期
|
static double |
randomDouble()
获得随机数[0, 1)
|
static double |
randomDouble(double limit)
获得指定范围内的随机数 [0,limit)
|
static double |
randomDouble(double min,
double max)
获得指定范围内的随机数
|
static double |
randomDouble(double min,
double max,
int scale,
RoundingMode roundingMode)
获得指定范围内的随机数
|
static double |
randomDouble(double limit,
int scale,
RoundingMode roundingMode)
获得指定范围内的随机数
|
static double |
randomDouble(int scale,
RoundingMode roundingMode)
获得指定范围内的随机数
|
static <T> T |
randomEle(List<T> list)
随机获得列表中的元素
|
static <T> T |
randomEle(List<T> list,
int limit)
随机获得列表中的元素
|
static <T> T |
randomEle(T[] array)
随机获得数组中的元素
|
static <T> T |
randomEle(T[] array,
int limit)
随机获得数组中的元素
|
static <T> List<T> |
randomEleList(List<T> source,
int count)
随机获得列表中的一定量的元素,返回List
|
static <T> List<T> |
randomEles(List<T> list,
int count)
随机获得列表中的一定量元素
|
static <T> Set<T> |
randomEleSet(Collection<T> collection,
int count)
随机获得列表中的一定量的不重复元素,返回Set
|
static int |
randomInt()
获得随机数[0, 1)
|
static int |
randomInt(int limit)
获得指定范围内的随机数 [0,limit)
|
static int |
randomInt(int min,
int max)
获得指定范围内的随机数
|
static int[] |
randomInts(int length)
创建指定长度的随机索引
|
static long |
randomLong()
获得随机数
|
static long |
randomLong(long limit)
获得指定范围内的随机数 [0,limit)
|
static long |
randomLong(long min,
long max)
获得指定范围内的随机数
|
static int |
randomNumber()
随机数字,数字为0~9单个数字
|
static String |
randomNumbers(int length)
获得一个只包含数字的字符串
|
static String |
randomString(int length)
获得一个随机的字符串(只包含数字和字符)
|
static String |
randomString(String str,
int length)
获得一个随机的字符串
|
static String |
randomStringUpper(int length)
获得一个随机的字符串(只包含数字和大写字符)
|
public static ThreadLocalRandom getRandom()
ThreadLocalRandompublic static Random getRandom(boolean isSecure)
isSecure - 是否为强随机数生成器 (RNG)RandomgetSecureRandom(),
getRandom()public static SecureRandom getSecureRandom()
SecureRandom,类提供加密的强随机数生成器 (RNG)SecureRandompublic static SecureRandom getSecureRandom(byte[] seed)
SecureRandom,类提供加密的强随机数生成器 (RNG)seed - 自定义随机种子SecureRandompublic static int randomInt(int min,
int max)
min - 最小数(包含)max - 最大数(不包含)public static int randomInt()
public static int randomInt(int limit)
limit - 限制随机数的范围,不包括这个数public static long randomLong(long min,
long max)
min - 最小数(包含)max - 最大数(不包含)public static long randomLong()
public static long randomLong(long limit)
limit - 限制随机数的范围,不包括这个数public static double randomDouble(double min,
double max)
min - 最小数(包含)max - 最大数(不包含)public static double randomDouble(double min,
double max,
int scale,
RoundingMode roundingMode)
min - 最小数(包含)max - 最大数(不包含)scale - 保留小数位数roundingMode - 保留小数的模式 RoundingModepublic static double randomDouble()
public static double randomDouble(int scale,
RoundingMode roundingMode)
scale - 保留小数位数roundingMode - 保留小数的模式 RoundingModepublic static double randomDouble(double limit)
limit - 限制随机数的范围,不包括这个数public static double randomDouble(double limit,
int scale,
RoundingMode roundingMode)
limit - 限制随机数的范围,不包括这个数scale - 保留小数位数roundingMode - 保留小数的模式 RoundingModepublic static BigDecimal randomBigDecimal()
public static BigDecimal randomBigDecimal(BigDecimal limit)
limit - 最大数(不包含)public static BigDecimal randomBigDecimal(BigDecimal min, BigDecimal max)
min - 最小数(包含)max - 最大数(不包含)public static byte[] randomBytes(int length)
length - 长度public static <T> T randomEle(List<T> list)
T - 元素类型list - 列表public static <T> T randomEle(List<T> list, int limit)
T - 元素类型list - 列表limit - 限制列表的前N项public static <T> T randomEle(T[] array)
T - 元素类型array - 列表public static <T> T randomEle(T[] array,
int limit)
T - 元素类型array - 列表limit - 限制列表的前N项public static <T> List<T> randomEles(List<T> list, int count)
T - 元素类型list - 列表count - 随机取出的个数public static <T> List<T> randomEleList(List<T> source, int count)
T - 元素类型source - 列表count - 随机取出的个数public static <T> Set<T> randomEleSet(Collection<T> collection, int count)
T - 元素类型collection - 列表count - 随机取出的个数IllegalArgumentException - 需要的长度大于给定集合非重复总数public static String randomString(int length)
length - 字符串的长度public static String randomStringUpper(int length)
length - 字符串的长度public static int[] randomInts(int length)
length - 长度public static String randomNumbers(int length)
length - 字符串的长度public static String randomString(String str, int length)
str - 随机字符选取的样本length - 字符串的长度public static int randomNumber()
public static char randomChar()
public static char randomChar(String baseString)
baseString - 随机字符选取的样本public static Color randomColor()
public static DateTime randomDay(int min, int max)
min - 偏移最小天,可以为负数表示过去的时间(包含)max - 偏移最大天,可以为负数表示过去的时间(不包含)public static DateTime randomDate(Date baseDate, Fields.DateField dateField, int min, int max)
baseDate - 基准日期dateField - 偏移的时间字段,例如时、分、秒等min - 偏移最小量,可以为负数表示过去的时间(包含)max - 偏移最大量,可以为负数表示过去的时间(不包含)public static boolean randomBoolean()
Copyright © 2020. All rights reserved.