Class StringFactory

  • All Implemented Interfaces:
    CandidateFactory<String>

    public class StringFactory
    extends AbstractCandidateFactory<String>
    General-purpose candidate factory for EAs that use a fixed-length String encoding. Generates random strings of a fixed length from a given alphabet.
    • Constructor Detail

      • StringFactory

        public StringFactory​(char[] alphabet,
                             int stringLength)
        Parameters:
        alphabet - The set of characters that can legally occur within a string generated by this factory.
        stringLength - The fixed length of all strings generated by this factory.
    • Method Detail

      • generateRandomCandidate

        public String generateRandomCandidate​(Random rng)
        Generates a random string of a pre-configured length. Each character is randomly selected from the pre-configured alphabet. The same character may appear multiple times and some characters may not appear at all.
        Parameters:
        rng - A source of randomness used to select characters to make up the string.
        Returns:
        A randomly generated string.