Class MathUtil

java.lang.Object
org.qiunet.utils.math.MathUtil

public class MathUtil extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    getBinaryVal(int val)
    得到一个数据的二进制表示
    static long
    getByRate(long val, long rate)
    得到val的 万分之rate .
    static String
    getHexVal(long val)
    数据的十六进制
    static String
    getHexVal(long val, int count)
    数据的十六进制
    static boolean
    isHit(int rate)
    万分比概率是否命中
    static boolean
    isPowerOfTwo(int val)
    是否是2的次幂数
    static <T extends IWeightObj>
    T
    randByWeight(List<T> list)
    在list 里面根据权重随机个数据
    static <T extends IWeightObj>
    T
    randByWeight(List<T> list, int totalRandNum)
    随机一个[0, totalRandNum)值 返回对应的对象.
    static double
    random(double start, double end)
    随机数计算 [start,end)
    static float
    random(float i)
    随机一个float
    static int
    random(int i)
    随机数计算 [0,i)
    static int
    random(int start, int end)
    随机数计算 [start,end)
    static int
    random(int start, int end, MathUtil.RandomType randomType)
    随机数计算 [start,end ) or ]
    static int
    toInt(long val)
    安全的强转 long to int

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • random

      public static int random(int start, int end, MathUtil.RandomType randomType)
      随机数计算 [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

      public static String getHexVal(long val)
      数据的十六进制
      Parameters:
      val -
      Returns:
    • getHexVal

      public static String getHexVal(long val, int count)
      数据的十六进制
      Parameters:
      val -
      count - 显示位数 右侧0补齐
      Returns:
    • getBinaryVal

      public static String getBinaryVal(int val)
      得到一个数据的二进制表示
      Parameters:
      val -
      Returns:
    • randByWeight

      public static <T extends IWeightObj> T randByWeight(List<T> list)
      在list 里面根据权重随机个数据
      Type Parameters:
      T -
      Parameters:
      list -
      Returns:
    • randByWeight

      public static <T extends IWeightObj> T randByWeight(List<T> list, int totalRandNum)
      随机一个[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: