Class RandomStringGenerator.Builder

    • Constructor Detail

    • Method Detail

      • filteredBy

        public RandomStringGenerator.Builder filteredBy​(CharacterPredicate... predicates)
        Limits the characters in the generated string to those that match at least one of the predicates supplied.

        Passing null or an empty array to this method will revert to the default behavior of allowing any character. Multiple calls to this method will replace the previously stored predicates.

        Parameters:
        predicates - the predicates, may be null or empty
        Returns:
        this, to allow method chaining
      • selectFrom

        public RandomStringGenerator.Builder selectFrom​(char... chars)
        Limits the characters in the generated string to those who match at supplied list of Character.

        Passing null or an empty array to this method will revert to the default behavior of allowing any character. Multiple calls to this method will replace the previously stored Character.

        Parameters:
        chars - set of predefined Characters for random string generation the Character can be, may be null or empty
        Returns:
        this, to allow method chaining
        Since:
        1.2
      • usingRandom

        public RandomStringGenerator.Builder usingRandom​(TextRandomProvider random)
        Overrides the default source of randomness. It is highly recommended that a random number generator library like Apache Commons RNG be used to provide the random number generation.

        When using Java 8 or later, TextRandomProvider is a functional interface and need not be explicitly implemented:

         
             UniformRandomProvider rng = RandomSource.create(...);
             RandomStringGenerator gen = new RandomStringGenerator.Builder()
                 .usingRandom(rng::nextInt)
                 // additional builder calls as needed
                 .build();
         
         

        Passing null to this method will revert to the default source of randomness.

        Parameters:
        random - the source of randomness, may be null
        Returns:
        this, to allow method chaining
      • withinRange

        public RandomStringGenerator.Builder withinRange​(char[]... pairs)
        Sets the array of minimum and maximum char allowed in the generated string. For example:
         
             char [][] pairs = {{'0','9'}};
             char [][] pairs = {{'a','z'}};
             char [][] pairs = {{'a','z'},{'0','9'}};
         
         
        Parameters:
        pairs - array of characters array, expected is to pass min, max pairs through this arg.
        Returns:
        this, to allow method chaining.