org.uncommons.watchmaker.framework.factories
Class StringFactory
java.lang.Object
org.uncommons.watchmaker.framework.factories.AbstractCandidateFactory<String>
org.uncommons.watchmaker.framework.factories.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.
- Author:
- Daniel Dyer
Constructor Summary |
StringFactory(char[] alphabet,
int stringLength)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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.
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.