I am answering this very late, but this is what really useful for new reader. This is a very simple and efficient way to get random VALID names. To do so, add maven repository in POM.xml

<dependency>
    <groupId>com.github.javafaker</groupId>
    <artifactId>javafaker</artifactId>
    <version>0.12</version>
</dependency>

And then use the Faker class as below in your Java code

Faker faker = new Faker();

String name = faker.name().fullName();
String firstName = faker.name().firstName();
String lastName = faker.name().lastName();

String streetAddress = faker.address().streetAddress();

Try printing the result using standard System.out.println();

For more reference Faker Lib

Answer from Gaurav Lad on Stack Overflow
🌐
GitHub
github.com › ajbrown › name-machine
GitHub - ajbrown/name-machine: Generate realistic random American male and female names. · GitHub
Name machine is a Java utility for generating random names with realistic probabilities of occurrence.
Starred by 57 users
Forked by 9 users
Languages   Java 93.7% | Groovy 6.3%
Discussions

Super Simple Name Generator! - Shared Code - JVM Gaming
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 ... More on jvm-gaming.org
🌐 jvm-gaming.org
9
0
March 22, 2015
[Java] I wrote a random name generator
Overall, looks pretty good! A few things I noticed: Make sure you are very intentional with your pluralization. For example, in the line Name names = new Name(), you have inconsistent pluralization. Which is it — one name, or multiple names? In Name, you have some places where you have hardcoded the length of some of your various arrays. This isn't good, because this means that if you want to update the contents of one of the arrays, you will have to change multiple places in your code, where you should only need to change one place in your code for such a change. Similarly, in UserInterface, you have one area that prints out a numbered list of all the actions that the user can choose from, but the logic that goes along with each of those actions is elsewhere in the file. It would be good to use a data structure such that if you needed to add an action, remove an action, or rearrange the actions, you could do so by only making one edit to the code, not multiple edits. More on reddit.com
🌐 r/learnprogramming
18
13
July 1, 2025
natural language processing - Random name generator in Java - Code Review Stack Exchange
I wrote working random name generator in Java. More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
June 13, 2017
Random Name Generator - Java you will use Java Collection objects to generate random names. This is useful when you have production data with customer names in it, but you need valid data in Dev/Test/Stage, but want to avoid having Personally Identifiable Information (PII) in these lower life cycles. You can use these random names to replace the PII
Answer to Random Name Generator - Java you will use Java More on chegg.com
🌐 chegg.com
1
January 9, 2020
🌐
Medium
reedanna.medium.com › creating-a-simple-random-generator-in-java-43d2ac47543c
Creating a Simple Random Generator in Java | by Anna Reed | Medium
January 8, 2021 - Probably at the random generation utility itself. To begin with, I imported the java.util.Random class and created a new Random instance that I named rand.
🌐
JVM Gaming
jvm-gaming.org › shared code
Super Simple Name Generator! - Shared Code - JVM Gaming
March 22, 2015 - 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 ...
🌐
Reddit
reddit.com › r/learnprogramming › [java] i wrote a random name generator
r/learnprogramming on Reddit: [Java] I wrote a random name generator
July 1, 2025 -

Hey there! I recently started learning java a couple weeks ago as my first language, mostly out of interest in developing some mods for minecraft. After getting comfortable with java, I intend to learn C# and pursue other interests involving game development.

At any rate, I've always loved coming up with unique names. So I thought why not challenge myself with writing a random name generator that doesn't just spit out nonsense. I feel comfortable calling the project complete for now although I could add more and more functionality, I do want to get on with continuing to learn.

I would appreciate feedback on my coding, even if it's a fairly simple project. Am I doing things moderately well? Does anything stand out as potentially problematic in the future if I carry on the way I have here? Am I writing too much useless or needless code? I am trying to ensure I don't solidify any bad habits or practices while I'm still learning fresh.

The project is at https://github.com/Vember/RandomNameGenerator

Greatly appreciate any feedback!

Top answer
1 of 2
3
Overall, looks pretty good! A few things I noticed: Make sure you are very intentional with your pluralization. For example, in the line Name names = new Name(), you have inconsistent pluralization. Which is it — one name, or multiple names? In Name, you have some places where you have hardcoded the length of some of your various arrays. This isn't good, because this means that if you want to update the contents of one of the arrays, you will have to change multiple places in your code, where you should only need to change one place in your code for such a change. Similarly, in UserInterface, you have one area that prints out a numbered list of all the actions that the user can choose from, but the logic that goes along with each of those actions is elsewhere in the file. It would be good to use a data structure such that if you needed to add an action, remove an action, or rearrange the actions, you could do so by only making one edit to the code, not multiple edits.
2 of 2
2
Actually quite a fun project, and it is obvious that you've had fun playing around with making the code - that's a good thing! This is only comments for the UserInterface, and mostly ideas for further improvements. I like the processCommand method, and you should take it further still, and make separate methods for each command - like generateRandom, generateWithLength, generateWithLetter, or what you prefer to name them, and then only let processCommand decide which of them to call. Also, not sure why you use Integer.valueOf to test the value of ints, usually writing if (command == 1) should be sufficient. You might want to use a switch-case for the commands instead of a chain of if-statements. It might make the code look better, something like: switch(command) { case 1 -> generateRandom(); case 2 -> generateWithLength(); case 3 -> generateWithLetter(); and so on. But it is a matter of taste. You could benefit from making a single method for reading a valid number from the input - something like: getValidInput(int[] numbers) that would only return one of the numbers in the array, or zero if something else was entered by the user. That would isolate your use of scanner to that method alone, and make the rest of the code easier to write without having to handle exceptions or different invalid inputs. It is always a good idea to have a lot of small methods that only do one thing - my own personal rule is that if I have more than two levels of if-statements or loops, I need to make a method to combine them. The less indentation the better :)
🌐
Open Hub
openhub.net › p › janag
The JaNaG - Java Name Generator Open Source Project on Open Hub
JaNaG (Java Name Generator) is a random name generator for role-games, authors, and the like. It is based on a name fragment database that creates relatively reasonably sounding names from different cultures/influences (e.g. elves, orcs, pseudo-old-German, etc.).
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java string › java – generate random string
Java - Generate Random String | Baeldung
May 11, 2024 - Generate Bounded and Unbounded Random Strings using plain Java and the Apache Commons Lang library.
Top answer
1 of 1
3

Consider Regex

Your WordChecker class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern and Matcher classes in java.util.regex that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:

public class WordChecker {
    private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
    private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");

    private static boolean onlyVowels(String input) {
        return VOWEL_PATTERN.matcher(input).matches();
    }

    private static boolean onlyConsonants(String input) {
        return CONSONANT_PATTERN.matcher(input).matches();
    }
}

Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("..."); As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.

For further reference look at the documentation here.

Use meaningful names; avoid deceptive names.

Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).

Leverage the API

One of the premier merits of using any language in particular is the available libraries. Unless this was done as an exercise the majority of the Dictionary class can be eliminated by using a HashMap.

🌐
YouTube
youtube.com › watch
Generate Random String Names in Java | Random Class - YouTube
Using Random class in Java, we can easily generate random values in runtime.www.codelikedude.com
Published   November 7, 2021
🌐
Coderanch
coderanch.com › t › 628031 › java › Randomizing-names-list
Randomizing names from a list (Beginning Java forum at Coderanch)
February 2, 2014 - Or you can try random numbers up to the size of your list of names and use those numbers as an index. For both those techniques you would have to put the names into a List. Selection from an ArrayList runs in constant time. Note the standard Java installation has several random classes; you might find something other than java.util.Random fits your purposes better.
🌐
GitHub
github.com › folkengine › java-random-name-generator
GitHub - folkengine/java-random-name-generator: Generates random names from syllables
March 21, 2016 - Generates random names from syllables. Contribute to folkengine/java-random-name-generator development by creating an account on GitHub.
Starred by 5 users
Forked by 2 users
Languages   Java 100.0% | Java 100.0%
🌐
GitHub
github.com › igr › nomen-est-omen
GitHub - igr/nomen-est-omen: Random names generator, with a style. · GitHub
"Your name is your destiny", so be sure you pick a good name. This Java library helps with generating some super-awesome random names that you can use for some unique IDs or passwords :)
Starred by 47 users
Forked by 4 users
Languages   Java
🌐
Reddit
reddit.com › r/javahelp › help fixing this random name generator
r/javahelp on Reddit: Help Fixing this Random Name Generator
March 17, 2015 -

Really new to Java, I appreciate all the constructive criticism you've got. My goal is to make a program that picks a name from a list, so I put them into an array, then added what I think should enable it to choose randomly, but I'm really stuck on getting the generator going. I'm using www.ideone.com to compile and execute it online but I keep getting errors. I found this post and I don't know if I just don't understand it or what, but it really didn't help me.

This is what I have so far:

String[] array = {"Sarah","Grace","Elizabeth","Jamie"};
    Random ran = new Random();
        System.out.println("You're up, " "!");

I also found this question but I'm having a lot of trouble decoding the answer s/he got

Thanks so much!

Edit: formatting

Top answer
1 of 3
1
From your StackOverflow link, this is the closest to your current code: String[] names = {"Bob", "Jill", "Tom", "Brandon"}; int index = Math.random() * (names.length - 1); String name = names[index]; System.out.println("Your random name is" + name + "now!"); Using Math.random() * names.length is a shortcut to creating a "new Random()" object. Math.random() will return a double between 0.0 and 1.0, so multiplying the random number by the length of your string will give you a proper index to access in the array. I added "names.length - 1" because if the random() were to return 1.0, the names[4] index doesn't exist and you would receive and IndexOutOfBoundsException. Edit: I tried running the code on your compiler and it's set to strict mode. Here's some code that actually works: String[] names = {"Bob", "Jill", "Tom", "Brandon"}; Long index = Math.round(Math.random() * (names.length - 1)); String name = names[index.intValue()]; System.out.println("Your random name is " + name + " now!");
2 of 3
1
I'm using www.ideone.com to compile and execute it online but I keep getting errors. What error are you getting? You could show them here so that others can help with it. At least point you in a right direction. One way by which you can use Random class is like so: import java.util.*; //Random public class RandomName{ public static void main(String[] args){ String[] names = {"Sarah","Grace","Elizabeth","Jamie"}; Random rand = new Random(); for(int i = 0; i < names.length; i++) System.out.println( names[rand.nextInt(4)] ); } }
🌐
Programiz
programiz.com › java-programming › examples › generate-random-string
Java Program to Create random strings
import java.util.Random; class ... random string builder StringBuilder sb = new StringBuilder(); // create an object of Random class Random random = new Random(); // specify length of random string int length = 7; for(int i = 0; i < length; i++) { // generate random index ...
🌐
SpigotMC
spigotmc.org › threads › how-to-generate-a-random-name-and-use-it.106171
How to generate a random name and use it? | SpigotMC - High Performance Minecraft Software
December 1, 2015 - Hey Spigot, I'm wondering how to generate a randomized name on a command so this is an example. public boolean onCommand(CommandSender s, Command c,...
🌐
CopyProgramming
copyprogramming.com › howto › random-name-generator-in-java
Random Name Generator in Java : Best Practices, Code Examples, and Latest Java Features
December 31, 2025 - A random name generator in Java is a Java class or service that programmatically creates random human names, usernames, or identifiers using libraries like java.util.Random, SecureRandom, and collections APIs.