Crypto: randomUUID() method
Web Crypto API
Web Crypto API
The **`randomUUID()`** method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator.
## Syntax
```js-nolint
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
## Browser compatibility
## See also
- [Web Crypto API](/docs/Web/API/Web_Crypto_API)
- Crypto.getRandomValues, a source for arbitrary amounts of secure random bytes.
source: MDN Web Docs mirror · page
Cite this
"Crypto: randomUUID() method". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy