Class RandomStringUtils
- java.lang.Object
-
- org.apache.commons.lang3.RandomStringUtils
-
public class RandomStringUtils extends java.lang.ObjectGenerates randomStrings.Use
secure()to get the singleton instance based onSecureRandom()which uses a secure random number generator implementing the default random number algorithm.Use
secureStrong()to get the singleton instance based onSecureRandom.getInstanceStrong()which uses an instance that was selected by using the algorithms/providers specified in thesecurerandom.strongAlgorithmsSecurityproperty.Use
insecure()to get the singleton instance based onThreadLocalRandom.current()which is not cryptographically secure. In addition, instances do not use a cryptographically random seed unless the system propertyjava.util.secureRandomSeedis set totrue.Starting in version 3.17.0, the method
secure()usesSecureRandom()instead ofSecureRandom.getInstanceStrong(), and addssecureStrong().Starting in version 3.16.0, this class uses
secure()for static methods and addsinsecure().Starting in version 3.15.0, this class uses
SecureRandom.getInstanceStrong()for static methods.Before version 3.15.0, this class used
ThreadLocalRandom.current()for static methods, which is not cryptographically secure.RandomStringUtils is intended for simple use cases. For more advanced use cases consider using Apache Commons Text's RandomStringGenerator instead.
The Apache Commons project provides Commons RNG dedicated to pseudo-random number generation, that may be a better choice for applications with more stringent requirements (performance and/or correctness).
Note that private high surrogate characters are ignored. These are Unicode characters that fall between the values 56192 (db80) and 56319 (dbff) as we don't know how to handle them. High and low surrogates are correctly dealt with - that is if a high surrogate is randomly chosen, 55296 (d800) to 56191 (db7f) then it is followed by a low surrogate. If a low surrogate is chosen, 56320 (dc00) to 57343 (dfff) then it is placed after a randomly chosen high surrogate.
#ThreadSafe#
- Since:
- 1.0
- See Also:
secure(),secureStrong(),insecure(),SecureRandom(),SecureRandom.getInstanceStrong(),ThreadLocalRandom.current(),RandomUtils
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]ALPHANUMERICAL_CHARSprivate static intASCII_0private static intASCII_9private static intASCII_Aprivate static intASCII_zprivate static intBASE_CACHE_SIZE_PADDINGprivate static intBITS_TO_BYTES_DIVISORprivate static intCACHE_PADDING_BITSprivate static RandomStringUtilsINSECUREprivate java.util.function.Supplier<RandomUtils>randomprivate static RandomStringUtilsSECUREprivate static RandomStringUtilsSECURE_STRONGprivate static java.util.function.Supplier<RandomUtils>SECURE_SUPPLIER
-
Constructor Summary
Constructors Modifier Constructor Description RandomStringUtils()Deprecated.TODO Make private in 4.0.privateRandomStringUtils(java.util.function.Supplier<RandomUtils> random)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static RandomStringUtilsinsecure()Gets the singleton instance based onThreadLocalRandom.current(); which is not cryptographically secure; usesecure()to use an algorithms/providers specified in thesecurerandom.strongAlgorithmsSecurityproperty.java.lang.Stringnext(int count)Creates a random string whose length is the number of characters specified.java.lang.Stringnext(int count, boolean letters, boolean numbers)Creates a random string whose length is the number of characters specified.java.lang.Stringnext(int count, char... chars)Creates a random string whose length is the number of characters specified.java.lang.Stringnext(int count, int start, int end, boolean letters, boolean numbers)Creates a random string whose length is the number of characters specified.java.lang.Stringnext(int count, int start, int end, boolean letters, boolean numbers, char... chars)Creates a random string based on a variety of options, using default source of randomness.java.lang.Stringnext(int count, java.lang.String chars)Creates a random string whose length is the number of characters specified.java.lang.StringnextAlphabetic(int count)Creates a random string whose length is the number of characters specified.java.lang.StringnextAlphabetic(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.java.lang.StringnextAlphanumeric(int count)Creates a random string whose length is the number of characters specified.java.lang.StringnextAlphanumeric(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.java.lang.StringnextAscii(int count)Creates a random string whose length is the number of characters specified.java.lang.StringnextAscii(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.java.lang.StringnextGraph(int count)Creates a random string whose length is the number of characters specified.java.lang.StringnextGraph(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.java.lang.StringnextNumeric(int count)Creates a random string whose length is the number of characters specified.java.lang.StringnextNumeric(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.java.lang.StringnextPrint(int count)Creates a random string whose length is the number of characters specified.java.lang.StringnextPrint(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.private java.util.Randomrandom()Gets the Random.static java.lang.Stringrandom(int count)Deprecated.static java.lang.Stringrandom(int count, boolean letters, boolean numbers)Deprecated.static java.lang.Stringrandom(int count, char... chars)Deprecated.static java.lang.Stringrandom(int count, int start, int end, boolean letters, boolean numbers)Deprecated.static java.lang.Stringrandom(int count, int start, int end, boolean letters, boolean numbers, char... chars)Deprecated.static java.lang.Stringrandom(int count, int start, int end, boolean letters, boolean numbers, char[] chars, java.util.Random random)Creates a random string based on a variety of options, using supplied source of randomness.static java.lang.Stringrandom(int count, java.lang.String chars)Deprecated.static java.lang.StringrandomAlphabetic(int count)Deprecated.static java.lang.StringrandomAlphabetic(int minLengthInclusive, int maxLengthExclusive)Deprecated.static java.lang.StringrandomAlphanumeric(int count)Deprecated.static java.lang.StringrandomAlphanumeric(int minLengthInclusive, int maxLengthExclusive)Deprecated.static java.lang.StringrandomAscii(int count)Deprecated.static java.lang.StringrandomAscii(int minLengthInclusive, int maxLengthExclusive)Deprecated.static java.lang.StringrandomGraph(int count)Deprecated.static java.lang.StringrandomGraph(int minLengthInclusive, int maxLengthExclusive)Deprecated.static java.lang.StringrandomNumeric(int count)Deprecated.static java.lang.StringrandomNumeric(int minLengthInclusive, int maxLengthExclusive)Deprecated.static java.lang.StringrandomPrint(int count)Deprecated.static java.lang.StringrandomPrint(int minLengthInclusive, int maxLengthExclusive)Deprecated.private RandomUtilsrandomUtils()Gets the RandomUtils.static RandomStringUtilssecure()Gets the singleton instance based onSecureRandom()which uses a secure random number generator (RNG) implementing the default random number algorithm.static RandomStringUtilssecureStrong()Gets the singleton instance based onSecureRandom.getInstanceStrong()which uses an algorithms/providers specified in thesecurerandom.strongAlgorithmsSecurityproperty.java.lang.StringtoString()
-
-
-
Field Detail
-
SECURE_SUPPLIER
private static final java.util.function.Supplier<RandomUtils> SECURE_SUPPLIER
-
INSECURE
private static RandomStringUtils INSECURE
-
SECURE
private static RandomStringUtils SECURE
-
SECURE_STRONG
private static RandomStringUtils SECURE_STRONG
-
ALPHANUMERICAL_CHARS
private static final char[] ALPHANUMERICAL_CHARS
-
ASCII_0
private static final int ASCII_0
- See Also:
- Constant Field Values
-
ASCII_9
private static final int ASCII_9
- See Also:
- Constant Field Values
-
ASCII_A
private static final int ASCII_A
- See Also:
- Constant Field Values
-
ASCII_z
private static final int ASCII_z
- See Also:
- Constant Field Values
-
CACHE_PADDING_BITS
private static final int CACHE_PADDING_BITS
- See Also:
- Constant Field Values
-
BITS_TO_BYTES_DIVISOR
private static final int BITS_TO_BYTES_DIVISOR
- See Also:
- Constant Field Values
-
BASE_CACHE_SIZE_PADDING
private static final int BASE_CACHE_SIZE_PADDING
- See Also:
- Constant Field Values
-
random
private final java.util.function.Supplier<RandomUtils> random
-
-
Constructor Detail
-
RandomStringUtils
@Deprecated public RandomStringUtils()
Deprecated.TODO Make private in 4.0.RandomStringUtilsinstances should NOT be constructed in standard programming. Instead, the class should be used asRandomStringUtils.random(5);.This constructor is public to permit tools that require a JavaBean instance to operate.
-
RandomStringUtils
private RandomStringUtils(java.util.function.Supplier<RandomUtils> random)
-
-
Method Detail
-
insecure
public static RandomStringUtils insecure()
Gets the singleton instance based onThreadLocalRandom.current(); which is not cryptographically secure; usesecure()to use an algorithms/providers specified in thesecurerandom.strongAlgorithmsSecurityproperty.The method
ThreadLocalRandom.current()is called on-demand.- Returns:
- the singleton instance based on
ThreadLocalRandom.current(). - Since:
- 3.16.0
- See Also:
ThreadLocalRandom.current(),secure()
-
random
@Deprecated public static java.lang.String random(int count)
Deprecated.Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of all characters.
- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
random
@Deprecated public static java.lang.String random(int count, boolean letters, boolean numbers)Deprecated.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- iftrue, generated string may include alphabetic characters.numbers- iftrue, generated string may include numeric characters.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
random
@Deprecated public static java.lang.String random(int count, char... chars)Deprecated.Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters specified.
- Parameters:
count- the length of random string to create.chars- the character array containing the set of characters to use, may be null.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
random
@Deprecated public static java.lang.String random(int count, int start, int end, boolean letters, boolean numbers)Deprecated.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- iftrue, generated string may include alphabetic characters.numbers- iftrue, generated string may include numeric characters.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
random
@Deprecated public static java.lang.String random(int count, int start, int end, boolean letters, boolean numbers, char... chars)Deprecated.Creates a random string based on a variety of options, using default source of randomness.This method has exactly the same semantics as
random(int,int,int,boolean,boolean,char[],Random), but instead of using an externally supplied source of randomness, it uses the internal staticRandominstance.- 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- iftrue, generated string may include alphabetic characters.numbers- iftrue, generated string may include numeric characters.chars- the set of chars to choose randoms from. Ifnull, then it will use the set of all chars.- Returns:
- the random string.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if there are not(end - start) + 1characters in the set array.java.lang.IllegalArgumentException- ifcount< 0.
-
random
public static java.lang.String random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, java.util.Random random)Creates a random string based on a variety of options, using supplied source of randomness.If start and end are both
0, start and end are set to' 'and'z', the ASCII printable characters, will be used, unless letters and numbers are bothfalse, in which case, start and end are set to0andCharacter.MAX_CODE_POINT.If set is not
null, characters between start and end are chosen.This method accepts a user-supplied
Randominstance to use as a source of randomness. By seeding a singleRandominstance with a fixed seed and using it for each call, the same random sequence of strings can be generated repeatedly and predictably.- Parameters:
count- the length of random string to create.start- the position in set of chars to start at (inclusive).end- the position in set of chars to end before (exclusive).letters- iftrue, generated string may include alphabetic characters.numbers- iftrue, generated string may include numeric characters.chars- the set of chars to choose randoms from, must not be empty. Ifnull, then it will use the set of all chars.random- a source of randomness.- Returns:
- the random string.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if there are not(end - start) + 1characters in the set array.java.lang.IllegalArgumentException- ifcount< 0 or the provided chars array is empty.- Since:
- 2.0
-
random
@Deprecated public static java.lang.String random(int count, java.lang.String chars)Deprecated.Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters specified by the string, must not be empty. If null, the set of all characters is used.
- Parameters:
count- the length of random string to create.chars- the String containing the set of characters to use, may be null, but must not be empty.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0 or the string is empty.
-
randomAlphabetic
@Deprecated public static java.lang.String randomAlphabetic(int count)
Deprecated.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.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
randomAlphabetic
@Deprecated public static java.lang.String randomAlphabetic(int minLengthInclusive, int maxLengthExclusive)Deprecated.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
-
randomAlphanumeric
@Deprecated public static java.lang.String randomAlphanumeric(int count)
Deprecated.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.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
randomAlphanumeric
@Deprecated public static java.lang.String randomAlphanumeric(int minLengthInclusive, int maxLengthExclusive)Deprecated.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
-
randomAscii
@Deprecated public static java.lang.String randomAscii(int count)
Deprecated.Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters whose ASCII value is between
32and126(inclusive).- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
randomAscii
@Deprecated public static java.lang.String randomAscii(int minLengthInclusive, int maxLengthExclusive)Deprecated.Creates a random string whose length is between the inclusive minimum and the exclusive maximum.Characters will be chosen from the set of characters whose ASCII value is between
32and126(inclusive).- 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
-
randomGraph
@Deprecated public static java.lang.String randomGraph(int count)
Deprecated.Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters which match the POSIX [:graph:] regular expression character class. This class contains all visible ASCII characters (i.e. anything except spaces and control characters).
- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.5
-
randomGraph
@Deprecated public static java.lang.String randomGraph(int minLengthInclusive, int maxLengthExclusive)Deprecated.Creates a random string whose length is between the inclusive minimum and the exclusive maximum.Characters will be chosen from the set of \p{Graph} characters.
- 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
@Deprecated public static java.lang.String randomNumeric(int count)
Deprecated.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.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
randomNumeric
@Deprecated public static java.lang.String randomNumeric(int minLengthInclusive, int maxLengthExclusive)Deprecated.Creates a random string whose length is between the inclusive minimum and the exclusive maximum.Characters will be chosen from the set of \p{Digit} characters.
- 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
-
randomPrint
@Deprecated public static java.lang.String randomPrint(int count)
Deprecated.Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters which match the POSIX [:print:] regular expression character class. This class includes all visible ASCII characters and spaces (i.e. anything except control characters).
- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.5
-
randomPrint
@Deprecated public static java.lang.String randomPrint(int minLengthInclusive, int maxLengthExclusive)Deprecated.Creates a random string whose length is between the inclusive minimum and the exclusive maximum.Characters will be chosen from the set of \p{Print} characters.
- 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
-
secure
public static RandomStringUtils secure()
Gets the singleton instance based onSecureRandom()which uses a secure random number generator (RNG) implementing the default random number algorithm.The method
SecureRandom()is called on-demand.- Returns:
- the singleton instance based on
SecureRandom(). - Since:
- 3.16.0
- See Also:
SecureRandom()
-
secureStrong
public static RandomStringUtils secureStrong()
Gets the singleton instance based onSecureRandom.getInstanceStrong()which uses an algorithms/providers specified in thesecurerandom.strongAlgorithmsSecurityproperty.The method
SecureRandom.getInstanceStrong()is called on-demand.- Returns:
- the singleton instance based on
SecureRandom.getInstanceStrong(). - Since:
- 3.17.0
- See Also:
SecureRandom.getInstanceStrong()
-
next
public java.lang.String next(int count)
Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of all characters.
- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.16.0
-
next
public java.lang.String next(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- iftrue, generated string may include alphabetic characters.numbers- iftrue, generated string may include numeric characters.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.16.0
-
next
public java.lang.String next(int count, char... chars)Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters specified.
- Parameters:
count- the length of random string to create.chars- the character array containing the set of characters to use, may be null.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.16.0
-
next
public java.lang.String next(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- iftrue, generated string may include alphabetic characters.numbers- iftrue, generated string may include numeric characters.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.16.0
-
next
public java.lang.String next(int count, int start, int end, boolean letters, boolean numbers, char... chars)Creates a random string based on a variety of options, using default source of randomness.This method has exactly the same semantics as
random(int,int,int,boolean,boolean,char[],Random), but instead of using an externally supplied source of randomness, it uses the internal staticRandominstance.- 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- iftrue, generated string may include alphabetic characters.numbers- iftrue, generated string may include numeric characters.chars- the set of chars to choose randoms from. Ifnull, then it will use the set of all chars.- Returns:
- the random string.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if there are not(end - start) + 1characters in the set array.java.lang.IllegalArgumentException- ifcount< 0.
-
next
public java.lang.String next(int count, java.lang.String chars)Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters specified by the string, must not be empty. If null, the set of all characters is used.
- Parameters:
count- the length of random string to create.chars- the String containing the set of characters to use, may be null, but must not be empty.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0 or the string is empty.- Since:
- 3.16.0
-
nextAlphabetic
public java.lang.String nextAlphabetic(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.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
nextAlphabetic
public java.lang.String nextAlphabetic(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
-
nextAlphanumeric
public java.lang.String nextAlphanumeric(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.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
nextAlphanumeric
public java.lang.String nextAlphanumeric(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
-
nextAscii
public java.lang.String nextAscii(int count)
Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters whose ASCII value is between
32and126(inclusive).- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
nextAscii
public java.lang.String nextAscii(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 characters whose ASCII value is between
32and126(inclusive).- 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
-
nextGraph
public java.lang.String nextGraph(int count)
Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters which match the POSIX [:graph:] regular expression character class. This class contains all visible ASCII characters (i.e. anything except spaces and control characters).
- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.5
-
nextGraph
public java.lang.String nextGraph(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 \p{Graph} characters.
- 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
-
nextNumeric
public java.lang.String nextNumeric(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.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.
-
nextNumeric
public java.lang.String nextNumeric(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 \p{Digit} characters.
- 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
-
nextPrint
public java.lang.String nextPrint(int count)
Creates a random string whose length is the number of characters specified.Characters will be chosen from the set of characters which match the POSIX [:print:] regular expression character class. This class includes all visible ASCII characters and spaces (i.e. anything except control characters).
- Parameters:
count- the length of random string to create.- Returns:
- the random string.
- Throws:
java.lang.IllegalArgumentException- ifcount< 0.- Since:
- 3.5, 3.16.0
-
nextPrint
public java.lang.String nextPrint(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 \p{Print} characters.
- 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.16.0
-
random
private java.util.Random random()
Gets the Random.- Returns:
- the Random.
-
randomUtils
private RandomUtils randomUtils()
Gets the RandomUtils.- Returns:
- the RandomUtils.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-