-
- All Implemented Interfaces:
public final class RandomServiceWrapper around Random that also contains some additional functions not covered by Random.
If two instances of this RandomService are created with the same seed, and the same sequence of method calls is made for each, then they will generate and return identical sequences of values.
Instances of RandomService are not cryptographically secure by default. Consider passing java.security.SecureRandom to the constructor of this RandomService to get a cryptographically secure pseudo-random generator.
-
-
Method Summary
Modifier and Type Method Description final IntegernextInt()Returns the next pseudorandom, uniformly distributed Int value from this random number generator's sequence. final IntegernextInt(Integer bound)Returns a pseudorandom, uniformly distributed Int value between 0(inclusive) and the specified bound (exclusive), drawn from this random number generator's sequence.final IntegernextInt(IntRange intRange)Returns a pseudorandom, uniformly distributed Int value within the specified int range (inclusive), drawn from this random number generator's sequence. final IntegernextInt(Integer min, Integer max)Returns a pseudorandom, uniformly distributed Int value between min (inclusive) and max (inclusive), drawn from this random number generator's sequence. final <T extends Any> TrandomValue(List<T> list)Returns a pseudo-randomly selected value from the list of values. final <T extends Any> TrandomValue(Array<T> array)Returns a pseudo-randomly selected value from the array of values. final CharacternextLetter(Boolean upper)Returns the next pseudorandom, uniformly distributed Char value that corresponds to a letter in the English alphabet. final StringrandomString(Integer length, Boolean numericalChars)Returns String with the specified length consisting of a pseudo-randomly generated English alphabet letters and optional numericalChars, or an empty string for a length < 1.final StringrandomString(Integer length, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars, Boolean numericalChars)Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer length, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars)Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer length, Locale locale, Boolean indexChars, Boolean auxiliaryChars)Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer length, Locale locale, Boolean indexChars)Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer length, Locale locale)Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer length)Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString()Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer min, Integer max, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars, Boolean numericalChars)Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer min, Integer max, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars)Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer min, Integer max, Locale locale, Boolean indexChars, Boolean auxiliaryChars)Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer min, Integer max, Locale locale, Boolean indexChars)Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer min, Integer max, Locale locale)Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal StringrandomString(Integer min, Integer max)Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal BooleannextBoolean()Returns the next pseudorandom, uniformly distributed Boolean value from this random number generator's sequence. final LongnextLong()Returns the next pseudorandom, uniformly distributed Long value from this random number generator's sequence. final LongnextLong(Long bound)Returns a pseudorandom, uniformly distributed Long value between 0(inclusive), and the specified bound value (exclusive), drawn from this random number generator's sequence.final FloatnextFloat()Returns the next pseudorandom, uniformly distributed Float value between 0.0and1.0from this random number generator's sequence.final DoublenextDouble()Returns the next pseudorandom, uniformly distributed Double value between 0.0and1.0from this random number generator's sequence.final CharacternextChar()Returns the next pseudorandom, uniformly distributed Char value, from this random number generator's sequence. final StringnextString(Integer length, Locale locale, Boolean auxiliaryChars, Boolean numericalChars)Returns String with the specified length (or an empty string for a length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalCharsfinal <E extends Enum<E>> EnextEnum()Returns a randomly selected enum entry of type E. final <E extends Enum<E>> EnextEnum(Class<E> enum)Returns a pseudo-randomly selected enum entry of type E. final <E extends Enum<E>> EnextEnum(Array<E> values)Returns a pseudo-randomly selected enum entry from an Array of E type values. final <E extends Enum<E>> EnextEnum(Class<E> enum, Function1<E, Boolean> predicate)Returns a pseudo-randomly selected enum class of type E based on predicate for E. final <E extends Enum<E>> EnextEnum(String excludeName)Returns a randomly selected enum entry of type E excluding a particular class by it's className. final StringnextUUID()Returns the next pseudorandom UUID as String taking the seed of this random. final <T extends Any> List<T>randomSublist(List<T> list, Integer size, Boolean shuffled)Returns a view of the portion of the list with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> List<T>randomSublist(List<T> list, Integer size)Returns a view of the portion of the list with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> List<T>randomSublist(List<T> list)Returns a view of the portion of the list with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> List<T>randomSublist(List<T> list, IntRange sizeRange, Boolean shuffled)Returns a view of the portion of the list with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> List<T>randomSublist(List<T> list, IntRange sizeRange)Returns a view of the portion of the list with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> Set<T>randomSubset(Set<T> set, Integer size, Boolean shuffled)Returns a portion of the set with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> Set<T>randomSubset(Set<T> set, Integer size)Returns a portion of the set with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> Set<T>randomSubset(Set<T> set)Returns a portion of the set with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.final <T extends Any> Set<T>randomSubset(Set<T> set, IntRange sizeRange, Boolean shuffled)Returns a portion of the set with pseudo-randomly generated fromIndexand (possibly)toIndexvalues.-
-
Method Detail
-
randomValue
final <T extends Any> T randomValue(List<T> list)
Returns a pseudo-randomly selected value from the list of values.
-
randomValue
final <T extends Any> T randomValue(Array<T> array)
Returns a pseudo-randomly selected value from the array of values.
-
nextLetter
final Character nextLetter(Boolean upper)
Returns the next pseudorandom, uniformly distributed Char value that corresponds to a letter in the English alphabet.
- Parameters:
upper- returns the Char in upper-case if set totrue, and in lower-case otherwise
-
randomString
final String randomString(Integer length, Boolean numericalChars)
Returns String with the specified length consisting of a pseudo-randomly generated English alphabet letters and optional numericalChars, or an empty string for a
length < 1.- Parameters:
length- the length of the resulting string.numericalChars- add additional numerical chars from 0 to 9 to the resulting string.
-
randomString
@JvmOverloads() final String randomString(Integer length, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars, Boolean numericalChars)
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
length- the length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.auxiliaryChars- add additional auxiliary chars to the resulting string as defined in Character_Elements.numericalChars- add additional numerical chars from 0 to 9 to the resulting string Default:false
-
randomString
@JvmOverloads() final String randomString(Integer length, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars)
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
length- the length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.auxiliaryChars- add additional auxiliary chars to the resulting string as defined in Character_Elements.
-
randomString
@JvmOverloads() final String randomString(Integer length, Locale locale, Boolean indexChars, Boolean auxiliaryChars)
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
length- the length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.auxiliaryChars- add additional auxiliary chars to the resulting string as defined in Character_Elements.
-
randomString
@JvmOverloads() final String randomString(Integer length, Locale locale, Boolean indexChars)
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
length- the length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.
-
randomString
@JvmOverloads() final String randomString(Integer length, Locale locale)
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
length- the length of the resulting string.locale- locale to use to generate the charset.
-
randomString
@JvmOverloads() final String randomString(Integer length)
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
length- the length of the resulting string.
-
randomString
@JvmOverloads() final String randomString()
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars
-
randomString
@JvmOverloads() final String randomString(Integer min, Integer max, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars, Boolean numericalChars)
Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if
randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
min- the minimum length of the resulting string.max- the maximum length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.auxiliaryChars- add additional auxiliary chars to the resulting string as defined in Character_Elements.numericalChars- add additional numerical chars from 0 to 9 to the resulting string Default:false
-
randomString
@JvmOverloads() final String randomString(Integer min, Integer max, Locale locale, Boolean indexChars, Boolean auxiliaryChars, Boolean punctuationChars)
Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if
randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
min- the minimum length of the resulting string.max- the maximum length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.auxiliaryChars- add additional auxiliary chars to the resulting string as defined in Character_Elements.
-
randomString
@JvmOverloads() final String randomString(Integer min, Integer max, Locale locale, Boolean indexChars, Boolean auxiliaryChars)
Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if
randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
min- the minimum length of the resulting string.max- the maximum length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.auxiliaryChars- add additional auxiliary chars to the resulting string as defined in Character_Elements.
-
randomString
@JvmOverloads() final String randomString(Integer min, Integer max, Locale locale, Boolean indexChars)
Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if
randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
min- the minimum length of the resulting string.max- the maximum length of the resulting string.locale- locale to use to generate the charset.indexChars- add additional index chars to the resulting string, as defined in Character_Elements.
-
randomString
@JvmOverloads() final String randomString(Integer min, Integer max, Locale locale)
Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if
randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
min- the minimum length of the resulting string.max- the maximum length of the resulting string.locale- locale to use to generate the charset.
-
randomString
@JvmOverloads() final String randomString(Integer min, Integer max)
Returns String with a randomLength withing the specified min and max boundaries (or an empty string for if
randomLength < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
min- the minimum length of the resulting string.max- the maximum length of the resulting string.
-
nextBoolean
final Boolean nextBoolean()
Returns the next pseudorandom, uniformly distributed Boolean value from this random number generator's sequence.
The values
trueandfalseare produced with (approximately) equal probability.
-
nextDouble
final Double nextDouble()
-
nextString
@Deprecated(message = "This function is deprecated and will be removed in future releases. Note that default value for 'length' param has changed from '100' to '24' in the new 'randomString' function.", replaceWith = @ReplaceWith(imports = {}, expression = "randomString"), level = DeprecationLevel.WARNING) final String nextString(Integer length, Locale locale, Boolean auxiliaryChars, Boolean numericalChars)
Returns String with the specified length (or an empty string for a
length < 1) consisting of pseudo-randomly generated characters in a given locale with optional auxiliaryChars and numericalChars- Parameters:
length- the length of the resulting stringlocale- locale to use to generate the charset.auxiliaryChars- add additional auxiliary chars to the resulting string as defined in Character_ElementsnumericalChars- add additional numerical chars from 0 to 9 to the resulting string
-
nextEnum
final <E extends Enum<E>> E nextEnum(Class<E> enum)
Returns a pseudo-randomly selected enum entry of type E.
-
nextEnum
final <E extends Enum<E>> E nextEnum(String excludeName)
Returns a randomly selected enum entry of type E excluding a particular class by it's className.
-
randomSublist
@JvmOverloads() final <T extends Any> List<T> randomSublist(List<T> list, Integer size, Boolean shuffled)
Returns a view of the portion of the list with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.- Parameters:
size- the desired size of the resulting list.shuffled- iftruethe list will be shuffled before extracting the sublist
-
randomSublist
@JvmOverloads() final <T extends Any> List<T> randomSublist(List<T> list, Integer size)
Returns a view of the portion of the list with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.- Parameters:
size- the desired size of the resulting list.
-
randomSublist
@JvmOverloads() final <T extends Any> List<T> randomSublist(List<T> list)
Returns a view of the portion of the list with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.
-
randomSublist
@JvmOverloads() final <T extends Any> List<T> randomSublist(List<T> list, IntRange sizeRange, Boolean shuffled)
Returns a view of the portion of the list with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.- Parameters:
sizeRange- the desired size range of the resulting list.shuffled- iftruethe list will be shuffled before extracting the sublist
-
randomSublist
@JvmOverloads() final <T extends Any> List<T> randomSublist(List<T> list, IntRange sizeRange)
Returns a view of the portion of the list with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.- Parameters:
sizeRange- the desired size range of the resulting list.
-
randomSubset
@JvmOverloads() final <T extends Any> Set<T> randomSubset(Set<T> set, Integer size, Boolean shuffled)
Returns a portion of the set with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.- Parameters:
size- the desired size of the resulting set.shuffled- iftruethe set will be shuffled before extracting the subset
-
randomSubset
@JvmOverloads() final <T extends Any> Set<T> randomSubset(Set<T> set, Integer size)
Returns a portion of the set with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.- Parameters:
size- the desired size of the resulting set.
-
randomSubset
@JvmOverloads() final <T extends Any> Set<T> randomSubset(Set<T> set)
Returns a portion of the set with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.
-
randomSubset
final <T extends Any> Set<T> randomSubset(Set<T> set, IntRange sizeRange, Boolean shuffled)
Returns a portion of the set with pseudo-randomly generated
fromIndexand (possibly)toIndexvalues.- Parameters:
sizeRange- the desired size range of the resulting list.shuffled- iftruethe set will be shuffled before extracting the subset
-
-
-
-