I have the following Java class:
import java.util.Random;
public class RandomNameGenerator {
private Random rand;
private static String[] prefixes = { "Ultimate", "Bloody", "Crooked",
"Hallowed", "Magnificent", "Heavy", "Jagged", "Grand", "Shiny",
"Rusty" };
private static String[] items = { "Chainsaw", "Towel", "Ping-Pong Ball",
"Longsword", "Scissors", "Dagger", "Blade", "Bow", "Axe", "Dagger",
"Spoon", "Fork", "Coat", "Chain Mail", "Plate Mail", "Cloak",
"Cape", "Mirror", "Cauldron", "Pouch", "Boots", "Shoes", "Greaves",
"Pants", "Robes", "Locket", "Ring", "Amulet", "Potion", "Fish",
"Teapot", "Hood", "Crown", "Cap", "Helmet" };
private static String[] addons = { "Glorious", "Bloody", "Prolonged",
"Bitter", "Wicked", "Furious" };
private static String[] postfixes1 = { "Destruction", "Feminism",
"Twilight", "Massacre", "Dread", "Terror", "Mutual Understanding",
"Spite", "Immobility", "Mediocrity", "Anger" };
private static String[] postfixes2 = { "the Occult", "the Captain",
"the Warrior", "the Hunter", "the Haunted", "the Dead",
"the Fallen", "the Hitchhiker", "the Wicked King", "the Grue" };
public RandomNameGenerator() {
rand = new Random(System.currentTimeMillis());
}
public String getRandomName() {
StringBuilder str = new StringBuilder();
if (rand.nextInt(100) < 10) {
str.append("+");
str.append(Integer.toString(rand.nextInt(10) + 1));
str.append(" ");
}
if (rand.nextInt(100) < 50) {
str.append(prefixes[rand.nextInt(prefixes.length)]);
str.append(" ");
}
str.append(items[rand.nextInt(items.length)]);
str.append(" of ");
if (rand.nextInt(postfixes1.length + postfixes2.length) > postfixes2.length) {
if (rand.nextInt(100) < 70) {
str.append(addons[rand.nextInt(addons.length)]);
str.append(" ");
}
str.append(postfixes1[rand.nextInt(postfixes1.length)]);
} else {
str.append(postfixes2[rand.nextInt(postfixes2.length)]);
}
return str.toString();
}
}
I use it in a small program to generate sample item names like
Shiny Dagger of the Haunted
Shoes of Immobility
Bow of Mediocrity
In general I get the results that I want, however I can't help but notice, that certain combinations pop up very frequently, for example
Ping-Pong Ball of the Occult
occurs very often.
Is there a design flaw that leads to this outcome? Is there a better way to format what I'm trying to achieve?
fur coat
orbronze teapot
orbiker jacket
instead ofjacket
. you do a lot of stuff with the length of your strings, could it be that the weight for that string is more because of it's length being longer than the others? \$\endgroup\$