Crypto.randomUUID()
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The randomUUID()
method of the Crypto
interface is used to generate a v4 UUID using a cryptographically secure random number generator.
Syntax
crypto.randomUUID()
Return value
A DOMString
containing a randomly generated, 36 character long v4 UUID.
Examples
The method is accessed through the global crypto
property.
/* Assuming that self.crypto.randomUUID() is available */
let uuid = self.crypto.randomUUID();
console.log(uuid); // for example "36b8f84d-df4e-4d49-b662-bcde71a8764f"
Specifications
Specification |
---|
Web Cryptography API # Crypto-method-randomUUID |
Browser compatibility
BCD tables only load in the browser
See also
Web Crypto API
crypto
to get aCrypto
object.Crypto.getRandomValues
, a source for arbitrary amounts of secure random bytes.