Crypto: randomUUID() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The randomUUID()
method of the Crypto
interface is used to generate a v4 UUID using a cryptographically secure random number generator.
Syntax
js
randomUUID()
Parameters
None.
Return value
A string containing a randomly generated, 36 character long v4 UUID.
Examples
js
/* 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
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
randomUUID() |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
- Web Crypto API
Crypto.getRandomValues
, a source for arbitrary amounts of secure random bytes.