Super Simple Name Generator!

       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:

That’s really neat! You’re doing fine, continue your programming endeavours!

An optimization:
You could store a static Random instance instead of recreating one every time you call generateName().
A suggestion:
It is also common code practice to also make variables camelCase.

Thank you for the tips! ;D

There’s also no point to the i variable. Just inline it.

Very true! Thank you for that aswell! ;D

I also frown upon printing to the output because now what if I want a generated name, but don’t want to clutter program output with context-less pseudologging output? I can’t. Tend towards not performing such side effects and letting the caller decide what they want to do.

The whole generate function reduces to such:


public static String generateName() {
    return Beginning[rand.nextInt(Beginning.length)]
         + Middle[rand.nextInt(Middle.length)]
         + End[rand.nextInt(End.length)];
}

Another thought provoker: hmm, those array lookups are almost like function calls themselves…

         Ah, sorry about that. I only had that there for the first test, forgot to take it out.

Thank you for the help as well. ;D

Another thing is, if it suits, you could make all of it not static and have an optional seed argument for the NameGenerator, passed to the rng, allowing for reproducible sequences of names.