deno.com

method Crypto.randomUUID

#Crypto.randomUUID(): `${string}-${string}-${string}-${string}-${string}`

Generates a random RFC 4122 version 4 UUID using a cryptographically secure random number generator.

Examples #

#
const uuid = crypto.randomUUID();
console.log(uuid);
// Example output: '36b8f84d-df4e-4d49-b662-bcde71a8764f'

The randomUUID method generates a version 4 UUID, which is purely random. If you require other versions of UUIDs, such as time-based (v1) or name-based (v3 and v5), consider using the @std/uuid package available at https://jsr.io/@std/uuid.

#
import { v1 } from 'jsr:@std/uuid';

// Generate a time-based UUID (v1)
const uuidV1 = v1.generate();
console.log(uuidV1);
// output: 'a0c74f7e-82f1-11eb-8dcd-0242ac130003'

Return Type #

`${string}-${string}-${string}-${string}-${string}`

A randomly generated, 36-character long v4 UUID.

See #