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
🌐
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 - ... Here, the giveName function accepts race and gender as arguments, and then uses an if/else statement to determine whether or not the provided race has gender specific names. If the race has unisex names, then the randomize function is called ...
Discussions

natural language processing - Random name generator in Java - Code Review Stack Exchange
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I wrote working random name generator in Java. More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
June 13, 2017
[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
java - How To Randomly Generate From A Given List? - Stack Overflow
The problem I'm running into is to randomly generate names from a specific list. I want my program to be able to only pick from these names: Bob, Jill, Tom, and Brandon. I tried studying arrays but I think that's a bit too far for me to learn yet. So far I think I have a general idea, but I'm not sure. import java... More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
YouTube
youtube.com › watch
How To Generate Random Names in Java - YouTube
Simple Java tutorial how to generate random names and values in Java ..
Published   January 20, 2026
🌐
GitHub
github.com › ajbrown › name-machine
GitHub - ajbrown/name-machine: Generate realistic random American male and female names. · GitHub
It can also be run on the command line to output random names: java -jar name-machine.jar 1000 females java -jar name-machine.jar 5000 · When generating names for both genders, there is a slightly higher chance of generating a female name than a male name. This is in line with the real-world male-to-female ratio in the United States.
Starred by 56 users
Forked by 9 users
Languages   Java 93.7% | Groovy 6.3%
🌐
YouTube
youtube.com › watch
random name picker in java - YouTube
Code in Java to pick a random name from an array.𝗗𝗼𝗻'𝘁 𝗳𝗼𝗿𝗴𝗲𝘁 𝘁𝗼 𝘀𝘂𝗯𝘀𝗰𝗿𝗶𝗯𝗲 𝗮𝗻𝗱 𝘀𝗺𝗮𝘀𝗵 𝘁𝗵𝗲 𝗯𝗲𝗹𝗹 𝗯𝘂𝘁𝘁𝗼𝗻!Download sourc...
Published   August 4, 2022
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.

🌐
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 :)
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java string › java – generate random string
Java - Generate Random String | Baeldung
May 11, 2024 - In this tutorial, we’re going to learn how to generate a random string in Java, first using the standard Java libraries, then using a Java 8 variant, and finally using the Apache Commons Lang library.
🌐
GitHub
gist.github.com › LordAmit › f91471536ca320395420
A random name generator written in Java. Did it for fun :| · GitHub
April 7, 2015 - A random name generator written in Java. Did it for fun :| - NameGenerator.java
🌐
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.
🌐
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 ...
🌐
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 ...
🌐
Chegg
chegg.com › engineering › computer science › computer science questions and answers › 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
Solved Random Name Generator - Java you will use Java | Chegg.com
June 24, 2019 - The program will need to perform the following tasks: • Display your name and email address as the first output · • Load a list of First names and Last names from a file (2 files is suggested) and load these into a Collection object (again 2 different objects is suggested) • Generate 20 new names by randomly selecting a First Name and a Last Name
🌐
CopyProgramming
copyprogramming.com › howto › random-name-generator-in-java
Random Name Generator in Java : Best Practices, Code Examples, and Latest Java Features
May 11, 2024 - A random name generator in Java can be implemented using either list-based names (realistic) or pattern-based syllables (invented but readable). The most reliable way is to store word lists in collections and use random indices to select combinations.
🌐
Reddit
reddit.com › r/javahelp › help fixing this random name generator
r/javahelp on Reddit: Help Fixing this Random Name Generator
October 19, 2014 -

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)] ); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › generating-random-numbers-in-java
Generating Random Numbers in Java - GeeksforGeeks
April 24, 2025 - // Generating random number using java.util.Random; import java.util.Random; public class Geeks{ public static void main(String[] args) { // Creating the instance of Random class Random r= new Random(); // Generate random integers in range 0 ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.randomgenerators.randomgeneratorfactory.name
RandomGeneratorFactory.Name Method (Java.Util.RandomGenerators) | Microsoft Learn
Microsoft makes no warranties, express or implied, with respect to the information provided here. Return the name of the algorithm used by the random number generator. [Android.Runtime.Register("name", "()Ljava/lang/String;", "", ApiSince=35)] public string? Name(); [<Android.Runtime.Register("name", "()Ljava/lang/String;", "", ApiSince=35)>] member this.Name : unit -> string ... Name of the algorithm. ... Return the name of the algorithm used by the random number generator. Java documentation for java.util.random.RandomGeneratorFactory.name().
🌐
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
August 18, 2025 - 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,...
🌐
Sentry
sentry.io › sentry answers › java › generating random numbers in java
Generating random numbers in Java | Sentry
September 15, 2024 - To generate a random number in a range between a given start and end number: Use the end - start of your range as the input. Add start to the result. For example, the following code returns a random number between -5 and 5: import java.util.Random; ...