Java Utility Library

Java UUID - randomUUID() Method



The java.util.UUID.randomUUID() method is used to retrieve a type 4 (pseudo randomly generated) UUID. The UUID is generated using a cryptographically strong pseudo random number generator.

Syntax

public static UUID randomUUID()

Parameters

No parameter is required.

Return Value

Returns a randomly generated UUID.

Exception

NA.

Example:

In the example below, the java.util.UUID.randomUUID() method is used to generate a random UUID.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a random UUID
    UUID uid = UUID.randomUUID();

    //printing the uuid
    System.out.println("The random UUID is: " + uid);  
  }
}

One of the possible outcome is:

The random UUID is: 32649400-bd91-41e3-90da-0fd7679c80c6

❮ Java.util - UUID