Java UUID randomUUID() Method



Description

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

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

Getting a Randomly generated UUID Example

The following example shows usage of Java UUID randomUUID() method to get a type 3 (name based) UUID based on the specified byte array. We've created a UUID object using randomUUID() method. Then we've printed the UUID.

 package com.tutorialspoint; import java.util.UUID; public class UUIDDemo { public static void main(String[] args) { // creating UUID UUID uid = UUID.randomUUID(); // checking the value of random UUID System.out.println("Random UUID value: "+uid); } } 

Output

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

 Random UUID value: f97dde36-9fa2-4f7c-8c3d-93efb61fbc79 
java_util_uuid.htm
Advertisements