Package org.qiunet.utils.math
Class MathUtil
java.lang.Object
org.qiunet.utils.math.MathUtil
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetBinaryVal(int val) 得到一个数据的二进制表示static longgetByRate(long val, long rate) 得到val的 万分之rate .static StringgetHexVal(long val) 数据的十六进制static StringgetHexVal(long val, int count) 数据的十六进制static booleanisHit(int rate) 万分比概率是否命中static booleanisPowerOfTwo(int val) 是否是2的次幂数static <T extends IWeightObj>
TrandByWeight(List<T> list) 在list 里面根据权重随机个数据static <T extends IWeightObj>
TrandByWeight(List<T> list, int totalRandNum) 随机一个[0, totalRandNum)值 返回对应的对象.static doublerandom(double start, double end) 随机数计算 [start,end)static floatrandom(float i) 随机一个floatstatic intrandom(int i) 随机数计算 [0,i)static intrandom(int start, int end) 随机数计算 [start,end)static intrandom(int start, int end, MathUtil.RandomType randomType) 随机数计算 [start,end ) or ]static inttoInt(long val) 安全的强转 long to int
-
Method Details
-
random
随机数计算 [start,end ) or ]- Parameters:
start-end-randomType-- Returns:
-
random
public static int random(int start, int end) 随机数计算 [start,end)- Parameters:
start-end-- Returns:
-
random
public static double random(double start, double end) 随机数计算 [start,end)- Parameters:
start-end-- Returns:
-
random
public static int random(int i) 随机数计算 [0,i)- Parameters:
i-- Returns:
-
random
public static float random(float i) 随机一个float- Parameters:
i-- Returns:
-
isPowerOfTwo
public static boolean isPowerOfTwo(int val) 是否是2的次幂数- Parameters:
val-- Returns:
-
getHexVal
数据的十六进制- Parameters:
val-- Returns:
-
getHexVal
数据的十六进制- Parameters:
val-count- 显示位数 右侧0补齐- Returns:
-
getBinaryVal
得到一个数据的二进制表示- Parameters:
val-- Returns:
-
randByWeight
在list 里面根据权重随机个数据- Type Parameters:
T-- Parameters:
list-- Returns:
-
randByWeight
随机一个[0, totalRandNum)值 返回对应的对象.- Type Parameters:
T-- Parameters:
list-totalRandNum- 随机总权重.- Returns:
-
getByRate
public static long getByRate(long val, long rate) 得到val的 万分之rate . (val * rate) / 10000;- Parameters:
val- 数值rate- 万分比 整数 1% 表示为100- Returns:
-
isHit
public static boolean isHit(int rate) 万分比概率是否命中- Parameters:
rate- 概率值- Returns:
-
toInt
public static int toInt(long val) 安全的强转 long to int- Parameters:
val-- Returns:
-