java.util.UUID.randomUUID() Method

Advertisements


Description

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

Declaration

Following is the declaration for java.util.UUID.randomUUID() method.

public static UUID randomUUID()

Parameters

  • NA

Return Value

The method call returns a randomly generated UUID.

Exception

  • NA

Example

The following example shows the usage of java.util.UUID.randomUUID()

package com.tutorialspoint;

import java.util.*;

public class UUIDDemo {
   public static void main(String[] args) {
      // creating UUID      
      UUID uid = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d");     
        
      // checking the value of random UUID
      System.out.println("Random UUID value: "+uid.randomUUID());    
   }    
}

Let us compile and run the above program, this will produce the following result.

Random UUID value: 046b6c7f-0b8a-43b9-b35d-6489e6daee91



Advertisements
Advertisements