程序包 cool.scx.util

类 RandomUtils

java.lang.Object
cool.scx.util.RandomUtils

public final class RandomUtils extends Object
用于生成简单的随机数
版本:
0.0.1
作者:
scx567888
  • 构造器详细资料

    • RandomUtils

      public RandomUtils()
  • 方法详细资料

    • randomString

      public static String randomString(int size, RandomUtils.PoolType poolType)
      获取随机的 字符串 注意!!! 此方法和 getUUID 不同 若需要获取 uuid 请使用 getUUID
      参数:
      size - 字符串 的长度
      poolType - 候选池类型
      返回:
      随机的 字符串
    • randomString

      public static String randomString(int size)
      获取随机的 字符串 (包含字母和数字)
      参数:
      size - 长度
      返回:
      随机的 字符串
    • randomString

      public static String randomString(int size, String pool)
      获取随机的 字符串
      参数:
      size - 长度
      pool - 候选池 (会被切割成单个字符)
      返回:
      随机的 字符串
    • randomString

      public static String randomString(int size, String[] pool)
      获取随机的 字符串
      参数:
      size - 长度
      pool - 候选池
      返回:
      随机的 字符串
    • randomUUID

      public static String randomUUID()
      获取 UUID
      返回:
      UUID
    • randomGet

      @SafeVarargs public static <T> T randomGet(T... array)
      随机从数组中取出一个元素
      类型参数:
      T - T
      参数:
      array - 数组
      返回:
      随机的元素
    • randomGet

      public static <T> T randomGet(List<T> list)
      随机从列表中取出一个元素
      类型参数:
      T - T
      参数:
      list - 列表
      返回:
      随机的元素
    • randomGet

      public static <T> T[] randomGet(T[] array, int size)
      随机从数组中取出 多个元素 (不会重复)
      类型参数:
      T - t
      参数:
      array - 数组
      size - 长度
      返回:
      a
    • randomGet

      public static <T> List<T> randomGet(List<T> list, int size)
      随机从数组中取出 多个元素 (不会重复)
      类型参数:
      T - a
      参数:
      list - 数组
      size - 长度
      返回:
      a
    • randomBoolean

      public static boolean randomBoolean()
    • randomBytes

      public static byte[] randomBytes(int size)
      生成一个新的随机 byte 数组
      参数:
      size - 长度
      返回:
      byte 数组
    • randomBytes

      public static void randomBytes(byte[] bytes)
      填充用户提供的 byte 数组, 范围 -128 (包含) 到 127 (包含)
      参数:
      bytes - bytes
    • randomFloat

      public static float randomFloat()
    • randomFloat

      public static float randomFloat(float bound)
    • randomFloat

      public static float randomFloat(float origin, float bound)
      返回随机数
      参数:
      origin - 起始 (包含)
      bound - 结束 (不包含)
      返回:
      int
    • randomDouble

      public static double randomDouble()
    • randomDouble

      public static double randomDouble(double bound)
    • randomDouble

      public static double randomDouble(double origin, double bound)
      返回随机数
      参数:
      origin - 起始 (包含)
      bound - 结束 (不包含)
      返回:
      int
    • randomInt

      public static int randomInt()
    • randomInt

      public static int randomInt(int bound)
    • randomInt

      public static int randomInt(int origin, int bound)
      返回随机数
      参数:
      origin - 起始 (包含)
      bound - 结束 (不包含)
      返回:
      int
    • randomLong

      public static long randomLong()
    • randomLong

      public static long randomLong(long bound)
    • randomLong

      public static long randomLong(long origin, long bound)
      返回随机数
      参数:
      origin - 起始 (包含)
      bound - 结束 (不包含)
      返回:
      int