Package jodd.util
Class RandomString
- java.lang.Object
-
- jodd.util.RandomString
-
public class RandomString extends java.lang.ObjectClass that generates random strings.
-
-
Field Summary
Fields Modifier and Type Field Description protected static char[]ALPHA_NUMERIC_RANGEprotected static char[]ALPHA_RANGEprotected static RandomStringINSTANCEprotected java.security.SecureRandomrnd
-
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 RandomStringget()Returns default instance ofRandomString.java.lang.Stringrandom(int count, char[] chars)Creates random string whose length is the number of characters specified.java.lang.Stringrandom(int count, char start, char end)Creates random string whose length is the number of characters specified.java.lang.Stringrandom(int count, java.lang.String chars)Creates random string whose length is the number of characters specified.java.lang.StringrandomAlpha(int count)Creates random string of characters.java.lang.StringrandomAlphaNumeric(int count)Creates random string of characters and digits.java.lang.StringrandomAscii(int count)Creates random string whose length is the number of characters specified.java.lang.StringrandomBase64(int count)Creates random string that contains only Base64 characters.java.lang.StringrandomNumeric(int count)Creates random string that consist only of numbers.java.lang.StringrandomRanges(int count, char... ranges)Creates random string whose length is the number of characters specified.
-
-
-
Field Detail
-
ALPHA_RANGE
protected static final char[] ALPHA_RANGE
-
ALPHA_NUMERIC_RANGE
protected static final char[] ALPHA_NUMERIC_RANGE
-
INSTANCE
protected static final RandomString INSTANCE
-
rnd
protected final java.security.SecureRandom rnd
-
-
Method Detail
-
get
public static RandomString get()
Returns default instance ofRandomString.
-
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 between32and126(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.
-
-