Package org.aoju.bus.core.toolkit
Class RandomKit
java.lang.Object
org.aoju.bus.core.toolkit.RandomKit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadLocalRandom获取随机数生成器对象 ThreadLocalRandom是JDK 7之后提供并发产生随机数,能够解决多个线程发生的竞争争夺static RandomgetRandom(boolean isSecure) 获取随机数产生器static SecureRandom获取SecureRandom,类提供加密的强随机数生成器 (RNG)static SecureRandomgetSecureRandom(byte[] seed) 获取SHA1PRNG的SecureRandom,类提供加密的强随机数生成器 (RNG) 注意:此方法获取的是伪随机序列发生器PRNG(pseudo-random number generator)static BigDecimal获得指定范围内的随机数[0, 1)static BigDecimalrandomBigDecimal(BigDecimal limit) 获得指定范围内的随机数 [0,limit)static BigDecimalrandomBigDecimal(BigDecimal min, BigDecimal max) 获得指定范围内的随机数static boolean获得随机Boolean值static byte[]randomBytes(int length) 随机bytesstatic char随机字母或数字,小写static charrandomChar(String baseString) 随机字符static char随机汉字('一'-'鿿')static DateTimerandomDate(Date baseDate, Fields.Type type, int min, int max) 以给定日期为基准,随机产生一个日期static DateTimerandomDay(int min, int max) 以当天为基准,随机产生一个日期static double获得随机数[0, 1)static doublerandomDouble(double limit) 获得指定范围内的随机数 [0,limit)static doublerandomDouble(double min, double max) 获得指定范围内的随机数static doublerandomDouble(double min, double max, int scale, RoundingMode roundingMode) 获得指定范围内的随机数static doublerandomDouble(double limit, int scale, RoundingMode roundingMode) 获得指定范围内的随机数static doublerandomDouble(int scale, RoundingMode roundingMode) 获得指定范围内的随机数static <T> T随机获得列表中的元素static <T> T随机获得列表中的元素static <T> TrandomEle(T[] array) 随机获得数组中的元素static <T> TrandomEle(T[] array, int limit) 随机获得数组中的元素static <T> List<T> randomEleList(List<T> source, int count) 随机获得列表中的一定量的元素,返回Liststatic <T> List<T> randomEles(List<T> list, int count) 随机获得列表中的一定量元素static <T> Set<T> randomEleSet(Collection<T> collection, int count) 随机获得列表中的一定量的不重复元素,返回Setstatic int获得随机数[0, 1)static intrandomInt(int limit) 获得指定范围内的随机数 [0,limit)static intrandomInt(int min, int max) 获得指定范围内的随机数static int[]randomInts(int length) 创建指定长度的随机索引static long获得随机数static longrandomLong(long limit) 获得指定范围内的随机数 [0,limit)static longrandomLong(long min, long max) 获得指定范围内的随机数static int随机数字,数字为0~9单个数字static StringrandomNumbers(int length) 获得一个只包含数字的字符串static StringrandomString(int length) 获得一个随机的字符串(只包含数字和字符)static StringrandomString(String text, int length) 获得一个随机的字符串static StringrandomStringUpper(int length) 获得一个随机的字符串(只包含数字和大写字符)static StringrandomStringWithout(int length, String elemData) 获得一个随机的字符串(只包含数字和小写字母) 并排除指定字符串
-
Constructor Details
-
RandomKit
public RandomKit()
-
-
Method Details
-
getRandom
获取随机数生成器对象 ThreadLocalRandom是JDK 7之后提供并发产生随机数,能够解决多个线程发生的竞争争夺- Returns:
ThreadLocalRandom
-
getRandom
-
getSecureRandom
获取SecureRandom,类提供加密的强随机数生成器 (RNG)- Returns:
SecureRandom
-
getSecureRandom
获取SHA1PRNG的SecureRandom,类提供加密的强随机数生成器 (RNG) 注意:此方法获取的是伪随机序列发生器PRNG(pseudo-random number generator)- Parameters:
seed- 随机数种子- Returns:
SecureRandom
-
randomInt
public static int randomInt(int min, int max) 获得指定范围内的随机数- Parameters:
min- 最小数(包含)max- 最大数(不包含)- Returns:
- 随机数
-
randomInt
public static int randomInt()获得随机数[0, 1)- Returns:
- 随机数
-
randomInt
public static int randomInt(int limit) 获得指定范围内的随机数 [0,limit)- Parameters:
limit- 限制随机数的范围,不包括这个数- Returns:
- 随机数
-
randomLong
public static long randomLong(long min, long max) 获得指定范围内的随机数- Parameters:
min- 最小数(包含)max- 最大数(不包含)- Returns:
- 随机数
-
randomLong
public static long randomLong()获得随机数- Returns:
- 随机数
-
randomLong
public static long randomLong(long limit) 获得指定范围内的随机数 [0,limit)- Parameters:
limit- 限制随机数的范围,不包括这个数- Returns:
- 随机数
-
randomDouble
public static double randomDouble(double min, double max) 获得指定范围内的随机数- Parameters:
min- 最小数(包含)max- 最大数(不包含)- Returns:
- 随机数
-
randomDouble
获得指定范围内的随机数- Parameters:
min- 最小数(包含)max- 最大数(不包含)scale- 保留小数位数roundingMode- 保留小数的模式RoundingMode- Returns:
- 随机数
-
randomDouble
public static double randomDouble()获得随机数[0, 1)- Returns:
- 随机数
-
randomDouble
获得指定范围内的随机数- Parameters:
scale- 保留小数位数roundingMode- 保留小数的模式RoundingMode- Returns:
- 随机数
-
randomDouble
public static double randomDouble(double limit) 获得指定范围内的随机数 [0,limit)- Parameters:
limit- 限制随机数的范围,不包括这个数- Returns:
- 随机数
-
randomDouble
获得指定范围内的随机数- Parameters:
limit- 限制随机数的范围,不包括这个数scale- 保留小数位数roundingMode- 保留小数的模式RoundingMode- Returns:
- 随机数
-
randomBigDecimal
-
randomBigDecimal
获得指定范围内的随机数 [0,limit)- Parameters:
limit- 最大数(不包含)- Returns:
- 随机数
-
randomBigDecimal
获得指定范围内的随机数- Parameters:
min- 最小数(包含)max- 最大数(不包含)- Returns:
- 随机数
-
randomBytes
public static byte[] randomBytes(int length) 随机bytes- Parameters:
length- 长度- Returns:
- bytes
-
randomEle
随机获得列表中的元素- Type Parameters:
T- 元素类型- Parameters:
list- 列表- Returns:
- 随机元素
-
randomEle
随机获得列表中的元素- Type Parameters:
T- 元素类型- Parameters:
list- 列表limit- 限制列表的前N项- Returns:
- 随机元素
-
randomEle
public static <T> T randomEle(T[] array) 随机获得数组中的元素- Type Parameters:
T- 元素类型- Parameters:
array- 列表- Returns:
- 随机元素
-
randomEle
public static <T> T randomEle(T[] array, int limit) 随机获得数组中的元素- Type Parameters:
T- 元素类型- Parameters:
array- 列表limit- 限制列表的前N项- Returns:
- 随机元素
-
randomEles
-
randomEleList
-
randomEleSet
随机获得列表中的一定量的不重复元素,返回Set- Type Parameters:
T- 元素类型- Parameters:
collection- 列表count- 随机取出的个数- Returns:
- 随机元素
- Throws:
IllegalArgumentException- 需要的长度大于给定集合非重复总数
-
randomString
获得一个随机的字符串(只包含数字和字符)- Parameters:
length- 字符串的长度- Returns:
- 随机字符串
-
randomString
-
randomStringUpper
获得一个随机的字符串(只包含数字和大写字符)- Parameters:
length- 字符串的长度- Returns:
- 随机字符串
-
randomStringWithout
-
randomInts
public static int[] randomInts(int length) 创建指定长度的随机索引- Parameters:
length- 长度- Returns:
- 随机索引
-
randomNumbers
获得一个只包含数字的字符串- Parameters:
length- 字符串的长度- Returns:
- 随机字符串
-
randomNumber
public static int randomNumber()随机数字,数字为0~9单个数字- Returns:
- 随机数字字符
-
randomChar
public static char randomChar()随机字母或数字,小写- Returns:
- 随机字符
-
randomChar
随机字符- Parameters:
baseString- 随机字符选取的样本- Returns:
- 随机字符
-
randomDay
以当天为基准,随机产生一个日期- Parameters:
min- 偏移最小天,可以为负数表示过去的时间(包含)max- 偏移最大天,可以为负数表示过去的时间(不包含)- Returns:
- 随机日期(随机天 , 其它时间不变)
-
randomDate
以给定日期为基准,随机产生一个日期- Parameters:
baseDate- 基准日期type- 偏移的时间字段,例如时、分、秒等min- 偏移最小量,可以为负数表示过去的时间(包含)max- 偏移最大量,可以为负数表示过去的时间(不包含)- Returns:
- 随机日期
-
randomBoolean
public static boolean randomBoolean()获得随机Boolean值- Returns:
- true or false
-
randomChinese
public static char randomChinese()随机汉字('一'-'鿿')- Returns:
- 随机的汉字字符
-