Class RandomUtils
- java.lang.Object
-
- org.apereo.cas.util.RandomUtils
-
public class RandomUtils extends java.lang.ObjectThis isRandomUtilsthat encapsulates common base64 calls and operations in one spot.- Since:
- 5.2.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSYSTEM_PROPERTY_SECURE_RANDOM_ALGSystem property to indicate the algorithm used for random number generation.
-
Constructor Summary
Constructors Constructor Description RandomUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgenerateSecureRandomId()Generate secure random id string.static java.security.SecureRandomgetNativeInstance()Get strong enough SecureRandom instance and of the checked exception.static doublenextDouble()Returns a random double within 0 - Double.MAX_VALUEstatic doublenextDouble(double startInclusive, double endInclusive)Next double and provide double.static intnextInt()Returns a random int within 0 - Integer.MAX_VALUE.static intnextInt(int startInclusive, int endExclusive)Returns a random integer within the specified range.static longnextLong()Next long between 0 and long's maximum value.static longnextLong(long startInclusive, long endExclusive)Next long and provide long.static java.lang.Stringrandom(int count, boolean letters, boolean numbers)Creates a random string whose length is the number of characters specified.static java.lang.Stringrandom(int count, int start, int end, boolean letters, boolean numbers)Creates a random string whose length is the number of characters specified.static java.lang.StringrandomAlphabetic(int count)Creates a random string whose length is the number of characters specified.static java.lang.StringrandomAlphabetic(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.static java.lang.StringrandomAlphanumeric(int count)Creates a random string whose length is the number of characters specified.static java.lang.StringrandomAlphanumeric(int minLengthInclusive, int maxLengthExclusive)Creates a random string whose length is between the inclusive minimum and the exclusive maximum.static java.lang.StringrandomNumeric(int count)Creates a random string whose length is the number of characters specified.
-
-
-
Field Detail
-
SYSTEM_PROPERTY_SECURE_RANDOM_ALG
public static final java.lang.String SYSTEM_PROPERTY_SECURE_RANDOM_ALG
System property to indicate the algorithm used for random number generation.- See Also:
- Constant Field Values
-
-
Method Detail
-
getNativeInstance
public static java.security.SecureRandom getNativeInstance()
Get strong enough SecureRandom instance and of the checked exception.- Returns:
- the strong instance
-
nextLong
public static long nextLong()
Next long between 0 and long's maximum value.- Returns:
- the long
-
nextLong
public static long nextLong(long startInclusive, long endExclusive)Next long and provide long.- Parameters:
startInclusive- the start inclusiveendExclusive- the end exclusive- Returns:
- the long
-
nextDouble
public static double nextDouble(double startInclusive, double endInclusive)Next double and provide double.- Parameters:
startInclusive- the start inclusiveendInclusive- the end inclusive- Returns:
- the double
-
nextDouble
public static double nextDouble()
Returns a random double within 0 - Double.MAX_VALUE
.- Returns:
- the random double
- Since:
- 3.5
- See Also:
nextDouble(double, double)
-
generateSecureRandomId
public static java.lang.String generateSecureRandomId()
Generate secure random id string.- Returns:
- the string
-
randomAlphabetic
public static java.lang.String randomAlphabetic(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
-
randomAlphabetic
public static java.lang.String randomAlphabetic(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 generatemaxLengthExclusive- the exclusive maximum length of the string to generate- Returns:
- the random string
- Since:
- 3.5
-
nextInt
public static int nextInt(int startInclusive, int endExclusive)Returns a random integer within the specified range.
- Parameters:
startInclusive- the smallest value that can be returned, must be non-negativeendExclusive- the upper bound (not included)- Returns:
- the random integer
- Throws:
java.lang.IllegalArgumentException- ifstartInclusive > endExclusiveor ifstartInclusiveis negative
-
nextInt
public static int nextInt()
Returns a random int within 0 - Integer.MAX_VALUE.- Returns:
- the random integer
- Since:
- 3.5
- See Also:
nextInt(int, int)
-
random
public static java.lang.String random(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 createletters- iftrue, generated string may include alphabetic charactersnumbers- iftrue, generated string may include numeric characters- Returns:
- the random string
-
random
public static java.lang.String random(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 createstart- the position in set of chars to start atend- the position in set of chars to end beforeletters- iftrue, generated string may include alphabetic charactersnumbers- iftrue, generated string may include numeric characters- Returns:
- the random string
-
randomAlphanumeric
public static java.lang.String randomAlphanumeric(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
-
randomAlphanumeric
public static java.lang.String randomAlphanumeric(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 generatemaxLengthExclusive- the exclusive maximum length of the string to generate- Returns:
- the random string
- Since:
- 3.5
-
randomNumeric
public static java.lang.String randomNumeric(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
-
-