Package 

Class RandomService

  • All Implemented Interfaces:

    
    public final class RandomService
    
                        

    Wrapper 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.

    • Constructor Detail

    • Method Detail

      • nextInt

         final Integer nextInt()

        Returns the next pseudorandom, uniformly distributed Int value from this random number generator's sequence.

      • nextInt

         final Integer nextInt(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.

      • nextInt

         final Integer nextInt(IntRange intRange)

        Returns a pseudorandom, uniformly distributed Int value within the specified int range (inclusive), drawn from this random number generator's sequence.

      • 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 to true, 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 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.
      • nextBoolean

         final Boolean nextBoolean()

        Returns the next pseudorandom, uniformly distributed Boolean value from this random number generator's sequence.

        The values true and false are produced with (approximately) equal probability.

      • nextLong

         final Long nextLong()

        Returns the next pseudorandom, uniformly distributed Long value from this random number generator's sequence.

      • nextLong

         final Long nextLong(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.

      • nextFloat

         final Float nextFloat()

        Returns the next pseudorandom, uniformly distributed Float value between 0.0 and 1.0 from this random number generator's sequence.

      • nextDouble

         final Double nextDouble()

        Returns the next pseudorandom, uniformly distributed Double value between 0.0 and 1.0 from this random number generator's sequence.

      • nextChar

         final Character nextChar()

        Returns the next pseudorandom, uniformly distributed Char value, from this random number generator's sequence.

      • 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 string
        locale - locale to use to generate the charset.
        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
      • nextEnum

         final <E extends Enum<E>> E nextEnum()

        Returns a randomly selected enum entry of type E.

      • 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 fromIndex and (possibly) toIndex values.

        Parameters:
        size - the desired size of the resulting list.
        shuffled - if true the 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 fromIndex and (possibly) toIndex values.

        Parameters:
        size - the desired size of the resulting list.
      • 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 fromIndex and (possibly) toIndex values.

        Parameters:
        sizeRange - the desired size range of the resulting list.
        shuffled - if true the 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 fromIndex and (possibly) toIndex values.

        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 fromIndex and (possibly) toIndex values.

        Parameters:
        size - the desired size of the resulting set.
        shuffled - if true the 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 fromIndex and (possibly) toIndex values.

        Parameters:
        size - the desired size of the resulting set.
      • 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 fromIndex and (possibly) toIndex values.

        Parameters:
        sizeRange - the desired size range of the resulting list.
        shuffled - if true the set will be shuffled before extracting the subset