Class RandomUtils


  • public class RandomUtils
    extends java.lang.Object
    This is RandomUtils that encapsulates common base64 calls and operations in one spot.
    Since:
    5.2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String SYSTEM_PROPERTY_SECURE_RANDOM_ALG
      System property to indicate the algorithm used for random number generation.
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String generateSecureRandomId()
      Generate secure random id string.
      static java.security.SecureRandom getNativeInstance()
      Get strong enough SecureRandom instance and of the checked exception.
      static double nextDouble()
      Returns a random double within 0 - Double.MAX_VALUE
      static double nextDouble​(double startInclusive, double endInclusive)
      Next double and provide double.
      static int nextInt()
      Returns a random int within 0 - Integer.MAX_VALUE.
      static int nextInt​(int startInclusive, int endExclusive)
      Returns a random integer within the specified range.
      static long nextLong()
      Next long between 0 and long's maximum value.
      static long nextLong​(long startInclusive, long endExclusive)
      Next long and provide long.
      static java.lang.String random​(int count, boolean letters, boolean numbers)
      Creates a random string whose length is the number of characters specified.
      static java.lang.String random​(int count, int start, int end, boolean letters, boolean numbers)
      Creates a random string whose length is the number of characters specified.
      static java.lang.String randomAlphabetic​(int count)
      Creates a random string whose length is the number of characters specified.
      static java.lang.String randomAlphabetic​(int minLengthInclusive, int maxLengthExclusive)
      Creates a random string whose length is between the inclusive minimum and the exclusive maximum.
      static java.lang.String randomAlphanumeric​(int count)
      Creates a random string whose length is the number of characters specified.
      static java.lang.String randomAlphanumeric​(int minLengthInclusive, int maxLengthExclusive)
      Creates a random string whose length is between the inclusive minimum and the exclusive maximum.
      static java.lang.String randomNumeric​(int count)
      Creates a random string whose length is the number of characters specified.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SYSTEM_PROPERTY_SECURE_RANDOM_ALG

        public static final java.lang.String SYSTEM_PROPERTY_SECURE_RANDOM_ALG
        System property to indicate the algorithm used for random number generation.
        See Also:
        Constant Field Values
    • Constructor Detail

      • RandomUtils

        public RandomUtils()
    • Method Detail

      • getNativeInstance

        public static java.security.SecureRandom getNativeInstance()
        Get strong enough SecureRandom instance and of the checked exception.
        Returns:
        the strong instance
      • nextLong

        public static long nextLong()
        Next long between 0 and long's maximum value.
        Returns:
        the long
      • nextLong

        public static long nextLong​(long startInclusive,
                                    long endExclusive)
        Next long and provide long.
        Parameters:
        startInclusive - the start inclusive
        endExclusive - the end exclusive
        Returns:
        the long
      • nextDouble

        public static double nextDouble​(double startInclusive,
                                        double endInclusive)
        Next double and provide double.
        Parameters:
        startInclusive - the start inclusive
        endInclusive - the end inclusive
        Returns:
        the double
      • nextDouble

        public static double nextDouble()

        Returns a random double within 0 - Double.MAX_VALUE

        .
        Returns:
        the random double
        Since:
        3.5
        See Also:
        nextDouble(double, double)
      • generateSecureRandomId

        public static java.lang.String generateSecureRandomId()
        Generate secure random id string.
        Returns:
        the string
      • randomAlphabetic

        public static java.lang.String randomAlphabetic​(int count)

        Creates a random string whose length is the number of characters specified.

        Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z).

        Parameters:
        count - the length of random string to create
        Returns:
        the random string
      • randomAlphabetic

        public static java.lang.String randomAlphabetic​(int minLengthInclusive,
                                                        int maxLengthExclusive)

        Creates a random string whose length is between the inclusive minimum and the exclusive maximum.

        Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z).

        Parameters:
        minLengthInclusive - the inclusive minimum length of the string to generate
        maxLengthExclusive - the exclusive maximum length of the string to generate
        Returns:
        the random string
        Since:
        3.5
      • nextInt

        public static int nextInt​(int startInclusive,
                                  int endExclusive)

        Returns a random integer within the specified range.

        Parameters:
        startInclusive - the smallest value that can be returned, must be non-negative
        endExclusive - the upper bound (not included)
        Returns:
        the random integer
        Throws:
        java.lang.IllegalArgumentException - if startInclusive > endExclusive or if startInclusive is negative
      • nextInt

        public static int nextInt()
        Returns a random int within 0 - Integer.MAX_VALUE.
        Returns:
        the random integer
        Since:
        3.5
        See Also:
        nextInt(int, int)
      • random

        public static java.lang.String random​(int count,
                                              boolean letters,
                                              boolean numbers)

        Creates a random string whose length is the number of characters specified.

        Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.

        Parameters:
        count - the length of random string to create
        letters - if true, generated string may include alphabetic characters
        numbers - if true, generated string may include numeric characters
        Returns:
        the random string
      • random

        public static java.lang.String random​(int count,
                                              int start,
                                              int end,
                                              boolean letters,
                                              boolean numbers)

        Creates a random string whose length is the number of characters specified.

        Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.

        Parameters:
        count - the length of random string to create
        start - the position in set of chars to start at
        end - the position in set of chars to end before
        letters - if true, generated string may include alphabetic characters
        numbers - if true, generated string may include numeric characters
        Returns:
        the random string
      • randomAlphanumeric

        public static java.lang.String randomAlphanumeric​(int count)

        Creates a random string whose length is the number of characters specified.

        Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z) and the digits 0-9.

        Parameters:
        count - the length of random string to create
        Returns:
        the random string
      • randomAlphanumeric

        public static java.lang.String randomAlphanumeric​(int minLengthInclusive,
                                                          int maxLengthExclusive)

        Creates a random string whose length is between the inclusive minimum and the exclusive maximum.

        Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z) and the digits 0-9.

        Parameters:
        minLengthInclusive - the inclusive minimum length of the string to generate
        maxLengthExclusive - the exclusive maximum length of the string to generate
        Returns:
        the random string
        Since:
        3.5
      • randomNumeric

        public static java.lang.String randomNumeric​(int count)

        Creates a random string whose length is the number of characters specified.

        Characters will be chosen from the set of numeric characters.

        Parameters:
        count - the length of random string to create
        Returns:
        the random string