Package jodd.util

Class RandomString


  • public class RandomString
    extends java.lang.Object
    Class that generates random strings.
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomString()
      Creates new random string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static RandomString get()
      Returns default instance of RandomString.
      java.lang.String random​(int count, char[] chars)
      Creates random string whose length is the number of characters specified.
      java.lang.String random​(int count, char start, char end)
      Creates random string whose length is the number of characters specified.
      java.lang.String random​(int count, java.lang.String chars)
      Creates random string whose length is the number of characters specified.
      java.lang.String randomAlpha​(int count)
      Creates random string of characters.
      java.lang.String randomAlphaNumeric​(int count)
      Creates random string of characters and digits.
      java.lang.String randomAscii​(int count)
      Creates random string whose length is the number of characters specified.
      java.lang.String randomBase64​(int count)
      Creates random string that contains only Base64 characters.
      java.lang.String randomNumeric​(int count)
      Creates random string that consist only of numbers.
      java.lang.String randomRanges​(int count, char... ranges)
      Creates 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

      • ALPHA_RANGE

        protected static final char[] ALPHA_RANGE
      • ALPHA_NUMERIC_RANGE

        protected static final char[] ALPHA_NUMERIC_RANGE
      • rnd

        protected final java.security.SecureRandom rnd
    • Constructor Detail

      • RandomString

        public RandomString()
        Creates new random string.
    • Method Detail

      • get

        public static RandomString get()
        Returns default instance of RandomString.
      • random

        public java.lang.String random​(int count,
                                       char[] chars)
        Creates random string whose length is the number of characters specified. Characters are chosen from the set of characters specified.
      • random

        public java.lang.String random​(int count,
                                       java.lang.String chars)
        Creates random string whose length is the number of characters specified. Characters are chosen from the set of characters specified.
      • random

        public java.lang.String random​(int count,
                                       char start,
                                       char end)
        Creates random string whose length is the number of characters specified. Characters are chosen from the provided range.
      • randomAscii

        public java.lang.String randomAscii​(int count)
        Creates random string whose length is the number of characters specified. Characters are chosen from the set of characters whose ASCII value is between 32 and 126 (inclusive).
      • randomNumeric

        public java.lang.String randomNumeric​(int count)
        Creates random string that consist only of numbers.
      • randomRanges

        public java.lang.String randomRanges​(int count,
                                             char... ranges)
        Creates random string whose length is the number of characters specified. Characters are chosen from the multiple sets defined by range pairs. All ranges must be in acceding order.
      • randomAlpha

        public java.lang.String randomAlpha​(int count)
        Creates random string of characters.
      • randomAlphaNumeric

        public java.lang.String randomAlphaNumeric​(int count)
        Creates random string of characters and digits.
      • randomBase64

        public java.lang.String randomBase64​(int count)
        Creates random string that contains only Base64 characters.