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:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Each 'x' can be a lower-case letter or digit. For example, the following is a UUID:
bb0748a6-2688-4868-82e6-3ec1d5cb13ae

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.