Simple Genetic algorithm
I am trying to write a simple genetic algorithm that automatically generates the string "Hello_World!" I used the code snipit from an earlier post to randomly generate a 12 character string using upper/lower case, exclamation points, and underscores.
Here's the code i have so far:
import java.util.*;
public class test {
private final static char[] chars;
private final static Random random;
static { //
chars = new char[52];
for (int i = 0; i < 26; i ++) {
chars = (char) (97 + i);
chars[i + 26] = (char) (65 + i);
chars[i + 1] = (char) (95);
chars[i + 2] = (char) (33);
}
random = new Random ();
}
private static String randomString (int length) {
char[] array = new char[length];
for (int i = 0; i < length; i ++) {
array = chars[random.nextInt (chars.length)];
}
return new String (array);
}
public static void main (String[] parameters) {
for (int i = 1; i < 10; i ++) {
System.out.println (randomString (12));
}
}
}
Now I need to write the fitness test. The way I plan on going about this is to get the ASCII values of the individual characters in the random string and compare them to the value of the characters in "Hello_World!" however I cannot figure out how to get those values from the random string. Any suggests are greatly appreciated.

