Class RandomUtils


  • @ThreadSafe
    public final class RandomUtils
    extends Object
    Random utilities.
    Author:
    aherscu
    • Field Detail

      • DEFAULT_RANDOM_STRING_LENGTH

        public static final int DEFAULT_RANDOM_STRING_LENGTH
        The default random string length.
        See Also:
        Constant Field Values
    • Method Detail

      • lastRandomAlphaNumeric

        public static String lastRandomAlphaNumeric​(String template)
        Fills a provided template with the last random value generated on current thread.
        Parameters:
        template - string template into which to insert the last random value; see MessageFormat
        Returns:
        the template filled with the last random value, or StringUtils.EMPTY if no such value exists
      • padRandomAlphaNumeric

        public static String padRandomAlphaNumeric​(String template,
                                                   int length)
        Fills a provided template with a random value such that the entire length of the returned string is as specified.
        Parameters:
        template - string template into which to insert a random value; see MessageFormat
        length - the desired length of the returned string
        Returns:
        the template filled with a RandomStringUtils.randomAlphanumeric(int)
        Throws:
        IllegalArgumentException - if the desired length is less that the length of the template filled with an empty string
      • randomAlphaNumeric

        public static String randomAlphaNumeric​(String template)
        Fills a provided template with a random value.
        Parameters:
        template - string template into which to insert a random value; see MessageFormat
        Returns:
        the template filled with a RandomStringUtils.randomAlphanumeric(int)
      • randomAlphaNumeric

        public static String randomAlphaNumeric​(String template,
                                                int randomStringLength)
        Fills a provided template with a random value.
        Parameters:
        template - string template into which to insert a random value; see MessageFormat
        randomStringLength - the random string length
        Returns:
        the template filled with a RandomStringUtils.randomAlphanumeric(int)
        Throws:
        IllegalArgumentException - if the randomStringLength is negative