public class RandomUtil extends Object
Constructor and Description |
---|
RandomUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
getCode()
获取一个4位数的随机code,字母小写
|
static String |
getCode(int length)
获取随机code,包含数字和字母
|
static int |
getInteger()
获取一个随机整数
|
static int |
getNumber()
获取长度为4的随机数
|
static int |
getNumber(int length)
获取指定长度的随机数,如果超过最大值则返回最大值
最大值:2147483647
|
static int |
getNumber(int a,
int b)
获取某个区间中的随机数[a,b)
|
static int |
getNumber$right(int a,
int b)
获取某个区间中的随机数[a,b]
|
static Boolean |
getProbability(double prob)
根据概率获取boolean,区间:[0 , prob]
填入的参数即为概率的百分比
|
static Boolean |
getProbability(double probL,
double probR)
根据概率获取boolean,区间:[probL , probR]
|
static Random |
getRandom() |
static char |
getRandomChar()
获取一个随机英文字符,小写
|
static <T> T |
getRandomElement(List<T> trr)
从集合中返回一个随机元素
|
static <T> T |
getRandomElement(T[] trr)
从数组中返回一个随机元素
|
static String |
getRandomString()
获取一串长度为32的字符串,默认大小写随机
|
static String |
getRandomString(int length)
获取一串指定长度的随机字符串,默认大小写随机
|
static String |
getRandomString(int length,
boolean randomCase)
获取一串指定长度的随机字符串
|
static String |
getUUID()
获取长度为32的UUID
|
static String |
numFormat(Number dnum,
String formatStr)
自定义数字格式化
|
static Color |
randomColor()
返回一个随机颜色
|
static String |
randomColor$hexString()
返回16进制颜色代码
|
static int[] |
randomColor$intArr()
返回一个长度为三的数组,三位分别代表了颜色的R、G、B
|
static String |
toFixed(Number dnum,
int length)
数字小数保留
|
public static Random RANDOM
public static Random getRandom()
public static int getNumber()
public static int getNumber(int length)
length
- public static int getInteger()
public static int getNumber(int a, int b)
public static int getNumber$right(int a, int b)
a
- b
- public static String getCode(int length)
length
- public static String getCode()
public static String getUUID()
public static char getRandomChar()
public static String getRandomString(int length, boolean randomCase)
length
- 字符串长度randomCase
- 是否开启随机大小写public static String getRandomString(int length)
length
- 字符串长度public static String getRandomString()
public static String toFixed(Number dnum, int length)
dnum
- 需要保留的小数length
- 小数保留位数public static String numFormat(Number dnum, String formatStr)
dnum
- formatStr
- public static Color randomColor()
public static int[] randomColor$intArr()
public static String randomColor$hexString()
public static Boolean getProbability(double probL, double probR)
probL
- 概率百分比区间的左参数,取值范围为0-1之间,对应了0%和100%probR
- 概率百分比区间的右参数,取值范围为0-1之间,对应了0%和100%public static Boolean getProbability(double prob)
prob
- 概率百分比的小数形式,参数范围0-1public static <T> T getRandomElement(T[] trr)
T
- trr
- public static <T> T getRandomElement(List<T> trr)
T
- trr
- Copyright © 2020. All rights reserved.