Class RandomUtil

java.lang.Object
org.drasyl.util.RandomUtil

public final class RandomUtil extends Object
Utility class for receiving pseudorandom values.
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte
    Returns a single pseudorandom byte.
    static byte[]
    randomBytes(int count)
    Returns an array of length count containing pseudorandom bytes.
    static int
    randomInt(int max)
    Returns a pseudorandom, uniformly distributed int value between 0 and max.
    static int
    randomInt(int min, int max)
    Returns a pseudorandom, uniformly distributed int value between min and max.
    static long
    randomLong(long max)
    Returns a pseudorandom, uniformly distributed long value between 0 and max.
    static long
    randomLong(long min, long max)
    Returns a pseudorandom, uniformly distributed long value between min and max.
    static String
    randomString(int length)
    Returns a string of the given length containing pseudorandom alphanumeric characters.

    Methods inherited from class java.lang.Object

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

    • randomInt

      public static int randomInt(int min, int max)
      Returns a pseudorandom, uniformly distributed int value between min and max.
      Parameters:
      min - The lowest value to return
      max - The highest value to return
      Returns:
      Pseudorandom int
      Throws:
      IllegalArgumentException - if min is greater then max
    • randomInt

      public static int randomInt(int max)
      Returns a pseudorandom, uniformly distributed int value between 0 and max.
      Parameters:
      max - The highest value to return
      Returns:
      Pseudorandom int
    • randomLong

      public static long randomLong(long min, long max)
      Returns a pseudorandom, uniformly distributed long value between min and max.
      Parameters:
      min - The lowest value to return
      max - The highest value to return
      Returns:
      Pseudorandom long
      Throws:
      IllegalArgumentException - if min is greater then max
    • randomLong

      public static long randomLong(long max)
      Returns a pseudorandom, uniformly distributed long value between 0 and max.
      Parameters:
      max - The highest value to return
      Returns:
      Pseudorandom long
    • randomBytes

      public static byte[] randomBytes(int count)
      Returns an array of length count containing pseudorandom bytes.
      Parameters:
      count - The length of the array
      Returns:
      Array containing pseudorandom bytes
    • randomByte

      public static byte randomByte()
      Returns a single pseudorandom byte.
      Returns:
      a pseudorandom byte
    • randomString

      public static String randomString(int length)
      Returns a string of the given length containing pseudorandom alphanumeric characters.
      Parameters:
      length - The length of the string
      Returns:
      string containing pseudorandom alphanumeric characters