I'm creating a space game and needed names to be randomly generated for my planets. The code below is not COMPLETELY random though, as you will have to provide your in own beginning middle and ends in the Arrays. I did it this way so I could easily edit the style of names, so they don't always look like a name from an old Nordic book. All you have to do is call NameGenerator.generateName(); anywhere in your code and it will return a name. I am still extremely newby at programming, but I finally managed to make something that works correctly. With only these few amount of items, if I did my math correctly, there can be a possible total of 6500 different combinations.
import java.util.Random;
public class NameGenerator {
private static String[] Beginning = { "Kr", "Ca", "Ra", "Mrok", "Cru",
"Ray", "Bre", "Zed", "Drak", "Mor", "Jag", "Mer", "Jar", "Mjol",
"Zork", "Mad", "Cry", "Zur", "Creo", "Azak", "Azur", "Rei", "Cro",
"Mar", "Luk" };
private static String[] Middle = { "air", "ir", "mi", "sor", "mee", "clo",
"red", "cra", "ark", "arc", "miri", "lori", "cres", "mur", "zer",
"marac", "zoir", "slamar", "salmar", "urak" };
private static String[] End = { "d", "ed", "ark", "arc", "es", "er", "der",
"tron", "med", "ure", "zur", "cred", "mur" };
private static Random rand = new Random();
public static String generateName() {
return Beginning[rand.nextInt(Beginning.length)] +
Middle[rand.nextInt(Middle.length)]+
End[rand.nextInt(End.length)];
}
}
In Game: