Class RandomUtil


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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.
    • Method Detail

      • 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
      • 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