Class RandomKit

java.lang.Object
com.iohao.net.common.kit.RandomKit

public final class RandomKit extends Object
Random number generation utilities.
Author:
渔民小镇
date:
2022-07-14
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    random(int end)
    Gets a random number within the specified range (0 ~ end)
    static int
    random(int start, int end)
    Gets a random number within the specified range
    static long
    random(long end)
    Gets a random number within the specified range (0 ~ end)
    static long
    random(long start, long end)
    Gets a random number within the specified range
    static boolean
    Randomly generates a boolean value
    static double
    Generate a random double value in the range [0.0, 1.0).
    static int
    randomEle(int[] array)
    Select a random element from the given int array.
    static <T> T
    randomEle(@NonNull T[] array)
    Select a random element from the given array.
    static <T> T
    randomEle(List<T> list)
    Select a random element from the given list.
    static int
    randomInt(int limit)
    Gets a random number within the specified range [0, limit)
    static int
    randomInt(int min, int max)
    Gets a random number within the specified range
    static long
    randomLong(long limit)
    Gets a random number within the specified range [0, limit)
    static long
    randomLong(long min, long max)
    Gets a random number within the specified range

    Methods inherited from class Object

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

    • randomInt

      public static int randomInt(int limit)
      Gets a random number within the specified range [0, limit)
      Parameters:
      limit - The limit of the random number range, exclusive.
      Returns:
      The random number.
    • randomInt

      public static int randomInt(int min, int max)
      Gets a random number within the specified range
      Parameters:
      min - Minimum number (inclusive)
      max - Maximum number (exclusive)
      Returns:
      The random number
    • randomLong

      public static long randomLong(long limit)
      Gets a random number within the specified range [0, limit)
      Parameters:
      limit - The limit of the random number range, exclusive.
      Returns:
      The random number
      Since:
      21.23
    • randomLong

      public static long randomLong(long min, long max)
      Gets a random number within the specified range
      Parameters:
      min - Minimum number (inclusive)
      max - Maximum number (exclusive)
      Returns:
      The random number
      Since:
      21.23
    • random

      public static int random(int start, int end)
      Gets a random number within the specified range
      Parameters:
      start - Starting value (inclusive)
      end - Ending value (inclusive)
      Returns:
      The random number
    • random

      public static int random(int end)
      Gets a random number within the specified range (0 ~ end)
      Parameters:
      end - Ending value (inclusive)
      Returns:
      The random number
    • random

      public static long random(long start, long end)
      Gets a random number within the specified range
      Parameters:
      start - Starting value (inclusive)
      end - Ending value (inclusive)
      Returns:
      The random number
      Since:
      21.23
    • random

      public static long random(long end)
      Gets a random number within the specified range (0 ~ end)
      Parameters:
      end - Ending value (inclusive)
      Returns:
      The random number
      Since:
      21.23
    • randomBoolean

      public static boolean randomBoolean()
      Randomly generates a boolean value
      Returns:
      The boolean value
    • randomEle

      public static <T> T randomEle(List<T> list)
      Select a random element from the given list.
      Type Parameters:
      T - the element type
      Parameters:
      list - the list to pick from
      Returns:
      a randomly selected element
    • randomEle

      public static <T> T randomEle(@NonNull T[] array)
      Select a random element from the given array.
      Type Parameters:
      T - the element type
      Parameters:
      array - the array to pick from
      Returns:
      a randomly selected element
    • randomEle

      public static int randomEle(int[] array)
      Select a random element from the given int array.
      Parameters:
      array - the int array to pick from
      Returns:
      a randomly selected element
    • randomDouble

      public static double randomDouble()
      Generate a random double value in the range [0.0, 1.0).
      Returns:
      a random double