程序包 dev.utils.common

类 RandomUtils

java.lang.Object
dev.utils.common.RandomUtils

public final class RandomUtils extends Object
detail: 随机工具类
作者:
Ttt
  • 方法概要

    修饰符和类型
    方法
    说明
    static double[]
    doubles(int streamSize, double randomNumberOrigin, double randomNumberBound)
    获取随机 double[]
    static String
    getRandom(char[] chars, int length)
    获取 char[] 内的随机数
    static int
    getRandom(int max)
    获取 0 - 最大随机数之间的随机数
    static int
    getRandom(int min, int max)
    获取两个数之间的随机数 ( 不含最大随机数, 需要 + 1)
    static String
    getRandom(String[] strings, int length)
    获取 String[] 内的随机数
    static String
    getRandom(String source, int length)
    获取自定义数据自定义长度的随机数
    static String
    获取大写字母自定义长度的随机数
    static String
    getRandomLetters(int length)
    获取大小写字母自定义长度的随机数
    static String
    获取小写字母自定义长度的随机数
    static String
    getRandomNumbers(int length)
    获取数字自定义长度的随机数
    static String
    获取数字、大小写字母自定义长度的随机数
    static int[]
    ints(int streamSize, int randomNumberOrigin, int randomNumberBound)
    获取随机 int[]
    static long[]
    longs(int streamSize, long randomNumberOrigin, long randomNumberBound)
    获取随机 long[]
    static boolean
    获取伪随机 boolean 值
    static boolean
    获取伪随机 boolean 值
    static byte[]
    nextBytes(byte[] data)
    获取伪随机 byte[]
    static byte[]
    nextBytes(Random random, byte[] data)
    获取伪随机 byte[]
    static double
    获取伪随机 double 值
    static double
    获取伪随机 double 值
    static double
    nextDoubleRange(double origin, double bound)
    获取指定范围 double 值
    static float
    获取伪随机 float 值
    static float
    nextFloat(Random random)
    获取伪随机 float 值
    static double
    获取伪随机高斯分布值
    static double
    获取伪随机高斯分布值
    static int
    获取伪随机 int 值
    static int
    nextInt(int number)
    获取伪随机 int 值 ( 该值介于 [0, n) 的区间 )
    static int
    nextInt(Random random)
    获取伪随机 int 值
    static int
    nextInt(Random random, int number)
    获取伪随机 int 值 ( 该值介于 [0, n) 的区间 )
    static int
    nextIntRange(int origin, int bound)
    获取指定范围 int 值
    static long
    获取伪随机 long 值
    static long
    nextLong(Random random)
    获取伪随机 long 值
    static long
    nextLongRange(long origin, long bound)
    获取指定范围 long 值
    static int[]
    shuffle(int[] ints)
    洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
    static int[]
    shuffle(int[] ints, int shuffleCount)
    洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
    static boolean
    shuffle(Object[] objects)
    洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
    static boolean
    shuffle(Object[] objects, int shuffleCount)
    洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
    static boolean
    shuffle2(Object[] objects)
    洗牌算法 ( 第二种 ) 随机置换指定的数组使用的默认源的随机性

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 方法详细资料

    • nextBoolean

      public static boolean nextBoolean(Random random)
      获取伪随机 boolean 值
      参数:
      random - Random
      返回:
      随机 boolean 值
    • nextBytes

      public static byte[] nextBytes(Random random, byte[] data)
      获取伪随机 byte[]
      参数:
      random - Random
      data - 随机数据源
      返回:
      随机 byte[]
    • nextDouble

      public static double nextDouble(Random random)
      获取伪随机 double 值
      参数:
      random - Random
      返回:
      随机 double 值
    • nextGaussian

      public static double nextGaussian(Random random)
      获取伪随机高斯分布值
      参数:
      random - Random
      返回:
      伪随机高斯分布值
    • nextFloat

      public static float nextFloat(Random random)
      获取伪随机 float 值
      参数:
      random - Random
      返回:
      随机 float 值
    • nextInt

      public static int nextInt(Random random)
      获取伪随机 int 值
      参数:
      random - Random
      返回:
      随机 int 值
    • nextInt

      public static int nextInt(Random random, int number)
      获取伪随机 int 值 ( 该值介于 [0, n) 的区间 )
      参数:
      random - Random
      number - 最大随机值
      返回:
      随机介于 [0, n) 的区间值
    • nextLong

      public static long nextLong(Random random)
      获取伪随机 long 值
      参数:
      random - Random
      返回:
      随机 long 值
    • nextBoolean

      public static boolean nextBoolean()
      获取伪随机 boolean 值
      返回:
      随机 boolean 值
    • nextBytes

      public static byte[] nextBytes(byte[] data)
      获取伪随机 byte[]
      参数:
      data - 随机数据源
      返回:
      随机 byte[]
    • nextDouble

      public static double nextDouble()
      获取伪随机 double 值
      返回:
      随机 double 值
    • nextGaussian

      public static double nextGaussian()
      获取伪随机高斯分布值
      返回:
      伪随机高斯分布值
    • nextFloat

      public static float nextFloat()
      获取伪随机 float 值
      返回:
      随机 float 值
    • nextInt

      public static int nextInt()
      获取伪随机 int 值
      返回:
      随机 int 值
    • nextInt

      public static int nextInt(int number)
      获取伪随机 int 值 ( 该值介于 [0, n) 的区间 )
      参数:
      number - 最大随机值
      返回:
      随机介于 [0, n) 的区间值
    • nextLong

      public static long nextLong()
      获取伪随机 long 值
      返回:
      随机 long 值
    • getRandomNumbers

      public static String getRandomNumbers(int length)
      获取数字自定义长度的随机数
      参数:
      length - 长度
      返回:
      随机字符串
    • getRandomLowerCaseLetters

      public static String getRandomLowerCaseLetters(int length)
      获取小写字母自定义长度的随机数
      参数:
      length - 长度
      返回:
      随机字符串
    • getRandomCapitalLetters

      public static String getRandomCapitalLetters(int length)
      获取大写字母自定义长度的随机数
      参数:
      length - 长度
      返回:
      随机字符串
    • getRandomLetters

      public static String getRandomLetters(int length)
      获取大小写字母自定义长度的随机数
      参数:
      length - 长度
      返回:
      随机字符串
    • getRandomNumbersAndLetters

      public static String getRandomNumbersAndLetters(int length)
      获取数字、大小写字母自定义长度的随机数
      参数:
      length - 长度
      返回:
      随机字符串
    • getRandom

      public static String getRandom(String source, int length)
      获取自定义数据自定义长度的随机数
      参数:
      source - 随机的数据源
      length - 长度
      返回:
      随机字符串
    • getRandom

      public static String getRandom(char[] chars, int length)
      获取 char[] 内的随机数
      参数:
      chars - 随机的数据源
      length - 需要最终长度
      返回:
      随机字符串
    • getRandom

      public static String getRandom(String[] strings, int length)
      获取 String[] 内的随机数
      参数:
      strings - 随机的数据源
      length - 需要最终长度
      返回:
      随机字符串
    • getRandom

      public static int getRandom(int max)
      获取 0 - 最大随机数之间的随机数
      参数:
      max - 最大随机数
      返回:
      随机介于 [0, max) 的区间值
    • getRandom

      public static int getRandom(int min, int max)
      获取两个数之间的随机数 ( 不含最大随机数, 需要 + 1)
      参数:
      min - 最小随机数
      max - 最大随机数
      返回:
      随机介于 [min, max) 的区间值
    • shuffle

      public static boolean shuffle(Object[] objects)
      洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
      参数:
      objects - 随机数据源
      返回:
      true success, false fail
    • shuffle

      public static boolean shuffle(Object[] objects, int shuffleCount)
      洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
      参数:
      objects - 随机数据源
      shuffleCount - 洗牌次数
      返回:
      true success, false fail
    • shuffle

      public static int[] shuffle(int[] ints)
      洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
      参数:
      ints - 随机数据源
      返回:
      随机 int[]
    • shuffle

      public static int[] shuffle(int[] ints, int shuffleCount)
      洗牌算法 ( 第一种 ) 随机置换指定的数组使用的默认源的随机性 ( 随机数据源小于三个, 则无效 )
      参数:
      ints - 随机数据源
      shuffleCount - 洗牌次数
      返回:
      随机 int[]
    • shuffle2

      public static boolean shuffle2(Object[] objects)
      洗牌算法 ( 第二种 ) 随机置换指定的数组使用的默认源的随机性
      参数:
      objects - 随机数据源
      返回:
      true success, false fail
    • nextIntRange

      public static int nextIntRange(int origin, int bound) throws IllegalArgumentException
      获取指定范围 int 值
      参数:
      origin - 开始值
      bound - 范围值
      返回:
      属于指定范围随机 int 值
      抛出:
      IllegalArgumentException - 参数错误
    • nextLongRange

      public static long nextLongRange(long origin, long bound) throws IllegalArgumentException
      获取指定范围 long 值
      参数:
      origin - 开始值
      bound - 范围值
      返回:
      属于指定范围随机 long 值
      抛出:
      IllegalArgumentException - 参数错误
    • nextDoubleRange

      public static double nextDoubleRange(double origin, double bound) throws IllegalArgumentException
      获取指定范围 double 值
      参数:
      origin - 开始值
      bound - 范围值
      返回:
      属于指定范围随机 double 值
      抛出:
      IllegalArgumentException - 参数错误
    • ints

      public static int[] ints(int streamSize, int randomNumberOrigin, int randomNumberBound)
      获取随机 int[]
      参数:
      streamSize - 数组长度
      randomNumberOrigin - 开始值
      randomNumberBound - 结束值 ( 最大值范围 )
      返回:
      指定范围随机 int[]
    • longs

      public static long[] longs(int streamSize, long randomNumberOrigin, long randomNumberBound)
      获取随机 long[]
      参数:
      streamSize - 数组长度
      randomNumberOrigin - 开始值
      randomNumberBound - 结束值 ( 最大值范围 )
      返回:
      指定范围随机 long[]
    • doubles

      public static double[] doubles(int streamSize, double randomNumberOrigin, double randomNumberBound)
      获取随机 double[]
      参数:
      streamSize - 数组长度
      randomNumberOrigin - 开始值
      randomNumberBound - 结束值 ( 最大值范围 )
      返回:
      指定范围随机 double[]