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,
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.