Random Name Generation

Have you ever needed a quick and dirty way to generate random names or identifiers? The UUID class may come in handy. UUID stands for Universally Unique IDentifier and has been around for a long time (since the days of mainframes).

A UUID is a 128 bit number that takes the following form:

Each 'x' can be a lower-case letter or digit. For example, the following is a UUID:

The total number of possible UUIDs is 16 32 which equals 340,282,366,920,938,463,463,374,607,431,768,211,456. Because of the massive size of the sample space it is HIGHLY unlikely that any two randomly generated UUIDs will be the same.

Let's look at some sample code for how to generate a random name using a UUID:
import java.util.UUID;

public class NameGenerator {
    public static String getRandomName() {
        return UUID.randomUUID().toString();

Pretty simple! The UUID class takes care of all the random number generation and formatting for you.