Package org.marketcetera.util.misc
Class RandomStrings
- java.lang.Object
-
- org.marketcetera.util.misc.RandomStrings
-
public final class RandomStrings extends Object
Utilities for random string generation. All random distributions are uniform.- Since:
- 0.6.0
- Version:
- $Id: RandomStrings.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_LEN_STR_ALNUMThe default maximum length of a randomly generated string whose characters are all Unicode code points that are letters or digits; the minimum length is 1.static intDEFAULT_LEN_STR_CHARSETThe default maximum length of a randomly generated string whose characters are all Unicode code points that can be encoded by some charset (supplied or implied); the minimum length is 1.static intDEFAULT_LEN_STR_DIGITThe default maximum length of a randomly generated string whose characters are all Unicode code points that are digits; the minimum length is 1.static intDEFAULT_LEN_STR_IDThe default maximum length of a randomly generated string whose characters are all Unicode code points; in addition, the first character is always a letter, the second is always a digit, and the rest (if any) are either letters or digits; the minimum length is 2.static intDEFAULT_LEN_STR_LETTERThe default maximum length of a randomly generated string whose characters are all Unicode code points that are letters; the minimum length is 1.static intDEFAULT_LEN_STR_VALIDThe default maximum length of a randomly generated string whose characters are all Unicode code points that are deemed valid byStringUtils.isValid(int); the minimum length is 1.private static RandomsGenerator
-
Constructor Summary
Constructors Modifier Constructor Description privateRandomStrings()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgenStr(UCPFilter filter, int len)Returns a generated string of the given length whose characters are all Unicode code points that meet the constraints of the given filter.static StringgenStrAlNum()Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_ALNUM) whose characters are all Unicode code points that are letters or digits.static StringgenStrAlNum(int len)Returns a randomly generated string of the given length whose characters are all Unicode code points that are letters or digits.static StringgenStrCharset(Charset cs)Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_CHARSET) whose characters are all Unicode code points that can be encoded by the given charset.static StringgenStrCharset(Charset cs, int len)Returns a randomly generated string of the given length whose characters are all Unicode code points that can be encoded by the given charset.static StringgenStrDefCharset()Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_CHARSET) whose characters are all Unicode code points that can be encoded by the default JVM charset.static StringgenStrDefCharset(int len)Returns a randomly generated string of the given length whose characters are all Unicode code points that can be encoded by the default JVM charset.static StringgenStrDigit()Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_DIGIT) whose characters are all Unicode code points that are digits.static StringgenStrDigit(int len)Returns a randomly generated string of the given length whose characters are all Unicode code points that are digits.static StringgenStrFileSystem()Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_CHARSET) whose characters are all Unicode code points that can be encoded by the current system file encoding/charset (as specified in the system propertyfile.encoding).static StringgenStrFileSystem(int len)Returns a randomly generated string of the given length whose characters are all Unicode code points that can be encoded by the current system file encoding/charset (as specified in the system propertyfile.encoding).static StringgenStrId()Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_ID) whose characters are all Unicode code points; in addition, the first character is always a letter, the second is always a digit, and the rest (if any) are either letters or digits.static StringgenStrId(int len)Returns a randomly generated string of the given length whose characters are all Unicode code points; in addition, the first character (if any) is always a letter, the second (if any) is always a digit, and the rest (if any) are either letters or digits.static StringgenStrLetter()Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_LETTER) whose characters are all Unicode code points that are letters.static StringgenStrLetter(int len)Returns a randomly generated string of the given length whose characters are all Unicode code points that are letters.static StringgenStrValid()Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_VALID) whose characters are all Unicode code points that are deemed valid byStringUtils.isValid(int).static StringgenStrValid(int len)Returns a randomly generated string of the given length whose characters are all Unicode code points that are deemed valid byStringUtils.isValid(int).static intgenUCP()Returns a randomly generated Unicode code point within the full range of valid Unicode scalar values.static intgenUCP(UCPFilter filter)Returns a randomly generated Unicode code point that meets the constraints of the given filter.static intgenUCPAlNum()Returns a randomly generated Unicode code point that is either a letter or a digit.static intgenUCPCharset(Charset cs)Returns a randomly generated Unicode code point that can be encoded by the given charset.static intgenUCPDefCharset()Returns a randomly generated Unicode code point that can be encoded by the default JVM charset.static intgenUCPDigit()Returns a randomly generated Unicode code point that is a digit.static intgenUCPFileSystem()Returns a randomly generated Unicode code point that can be encoded by the current system file encoding/charset (as specified in the system propertyfile.encoding).static intgenUCPLetter()Returns a randomly generated Unicode code point that is a letter.static intgenUCPValid()Returns a randomly generated Unicode code point that is deemed valid byStringUtils.isValid(int).static voidresetGeneratorFixed()Resets the random number generator used by this class to a fixed seed value, which henceforth results in a repeatable, deterministic sequence of random code points and strings.static longresetGeneratorRandom()Resets the random number generator used by this class to a random seed value, and returns that value.static voidresetGeneratorRandom(long seed)Resets the random number generator used by this class to the given seed value, which henceforth results in a repeatable, deterministic sequence of random code points and strings.
-
-
-
Field Detail
-
DEFAULT_LEN_STR_CHARSET
public static final int DEFAULT_LEN_STR_CHARSET
The default maximum length of a randomly generated string whose characters are all Unicode code points that can be encoded by some charset (supplied or implied); the minimum length is 1.- See Also:
- Constant Field Values
-
DEFAULT_LEN_STR_VALID
public static final int DEFAULT_LEN_STR_VALID
The default maximum length of a randomly generated string whose characters are all Unicode code points that are deemed valid byStringUtils.isValid(int); the minimum length is 1.- See Also:
- Constant Field Values
-
DEFAULT_LEN_STR_DIGIT
public static final int DEFAULT_LEN_STR_DIGIT
The default maximum length of a randomly generated string whose characters are all Unicode code points that are digits; the minimum length is 1.- See Also:
- Constant Field Values
-
DEFAULT_LEN_STR_LETTER
public static final int DEFAULT_LEN_STR_LETTER
The default maximum length of a randomly generated string whose characters are all Unicode code points that are letters; the minimum length is 1.- See Also:
- Constant Field Values
-
DEFAULT_LEN_STR_ALNUM
public static final int DEFAULT_LEN_STR_ALNUM
The default maximum length of a randomly generated string whose characters are all Unicode code points that are letters or digits; the minimum length is 1.- See Also:
- Constant Field Values
-
DEFAULT_LEN_STR_ID
public static final int DEFAULT_LEN_STR_ID
The default maximum length of a randomly generated string whose characters are all Unicode code points; in addition, the first character is always a letter, the second is always a digit, and the rest (if any) are either letters or digits; the minimum length is 2.- See Also:
- Constant Field Values
-
sGenerator
private static Random sGenerator
-
-
Method Detail
-
resetGeneratorRandom
public static void resetGeneratorRandom(long seed)
Resets the random number generator used by this class to the given seed value, which henceforth results in a repeatable, deterministic sequence of random code points and strings.- Parameters:
seed- The seed.
-
resetGeneratorRandom
public static long resetGeneratorRandom()
Resets the random number generator used by this class to a random seed value, and returns that value.- Returns:
- The seed.
-
resetGeneratorFixed
public static void resetGeneratorFixed()
Resets the random number generator used by this class to a fixed seed value, which henceforth results in a repeatable, deterministic sequence of random code points and strings.
-
genUCP
public static int genUCP()
Returns a randomly generated Unicode code point within the full range of valid Unicode scalar values.- Returns:
- The code point.
-
genUCP
public static int genUCP(UCPFilter filter)
Returns a randomly generated Unicode code point that meets the constraints of the given filter.- Parameters:
filter- The filter.- Returns:
- The code point.
-
genUCPCharset
public static int genUCPCharset(Charset cs)
Returns a randomly generated Unicode code point that can be encoded by the given charset.- Parameters:
cs- The charset.- Returns:
- The code point.
-
genUCPDefCharset
public static int genUCPDefCharset()
Returns a randomly generated Unicode code point that can be encoded by the default JVM charset.- Returns:
- The code point.
-
genUCPFileSystem
public static int genUCPFileSystem()
Returns a randomly generated Unicode code point that can be encoded by the current system file encoding/charset (as specified in the system propertyfile.encoding).- Returns:
- The code point.
-
genUCPValid
public static int genUCPValid()
Returns a randomly generated Unicode code point that is deemed valid byStringUtils.isValid(int).- Returns:
- The code point.
-
genUCPDigit
public static int genUCPDigit()
Returns a randomly generated Unicode code point that is a digit.- Returns:
- The code point.
-
genUCPLetter
public static int genUCPLetter()
Returns a randomly generated Unicode code point that is a letter.- Returns:
- The code point.
-
genUCPAlNum
public static int genUCPAlNum()
Returns a randomly generated Unicode code point that is either a letter or a digit.- Returns:
- The code point.
-
genStr
public static String genStr(UCPFilter filter, int len)
Returns a generated string of the given length whose characters are all Unicode code points that meet the constraints of the given filter.- Parameters:
filter- The filter.len- The length (in code points).- Returns:
- The string.
-
genStrCharset
public static String genStrCharset(Charset cs, int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points that can be encoded by the given charset.- Parameters:
cs- The charset.len- The length (in code points).- Returns:
- The string.
-
genStrDefCharset
public static String genStrDefCharset(int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points that can be encoded by the default JVM charset.- Parameters:
len- The length (in code points).- Returns:
- The string.
-
genStrFileSystem
public static String genStrFileSystem(int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points that can be encoded by the current system file encoding/charset (as specified in the system propertyfile.encoding).- Parameters:
len- The length (in code points).- Returns:
- The string.
-
genStrValid
public static String genStrValid(int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points that are deemed valid byStringUtils.isValid(int).- Parameters:
len- The length (in code points).- Returns:
- The string.
-
genStrDigit
public static String genStrDigit(int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points that are digits.- Parameters:
len- The length (in code points).- Returns:
- The string.
-
genStrLetter
public static String genStrLetter(int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points that are letters.- Parameters:
len- The length (in code points).- Returns:
- The string.
-
genStrAlNum
public static String genStrAlNum(int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points that are letters or digits.- Parameters:
len- The length (in code points).- Returns:
- The string.
-
genStrId
public static String genStrId(int len)
Returns a randomly generated string of the given length whose characters are all Unicode code points; in addition, the first character (if any) is always a letter, the second (if any) is always a digit, and the rest (if any) are either letters or digits.- Parameters:
len- The length (in code points).- Returns:
- The string.
-
genStrCharset
public static String genStrCharset(Charset cs)
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_CHARSET) whose characters are all Unicode code points that can be encoded by the given charset.- Parameters:
cs- The charset.- Returns:
- The string.
-
genStrDefCharset
public static String genStrDefCharset()
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_CHARSET) whose characters are all Unicode code points that can be encoded by the default JVM charset.- Returns:
- The string.
-
genStrFileSystem
public static String genStrFileSystem()
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_CHARSET) whose characters are all Unicode code points that can be encoded by the current system file encoding/charset (as specified in the system propertyfile.encoding).- Returns:
- The string.
-
genStrValid
public static String genStrValid()
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_VALID) whose characters are all Unicode code points that are deemed valid byStringUtils.isValid(int).- Returns:
- The string.
-
genStrDigit
public static String genStrDigit()
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_DIGIT) whose characters are all Unicode code points that are digits.- Returns:
- The string.
-
genStrLetter
public static String genStrLetter()
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_LETTER) whose characters are all Unicode code points that are letters.- Returns:
- The string.
-
genStrAlNum
public static String genStrAlNum()
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_ALNUM) whose characters are all Unicode code points that are letters or digits.- Returns:
- The string.
-
genStrId
public static String genStrId()
Returns a randomly generated string of random length (bound byDEFAULT_LEN_STR_ID) whose characters are all Unicode code points; in addition, the first character is always a letter, the second is always a digit, and the rest (if any) are either letters or digits.- Returns:
- The string.
-
-