diff --git a/benchmark/crypto/randomUUID.js b/benchmark/crypto/randomUUID.js new file mode 100644 index 00000000000000..cca05242874738 --- /dev/null +++ b/benchmark/crypto/randomUUID.js @@ -0,0 +1,17 @@ +'use strict'; + +const common = require('../common.js'); +const { randomUUID } = require('crypto'); + +const bench = common.createBenchmark(main, { + n: [1e7], + disableEntropyCache: [0, 1], +}); + +function main({ n, disableEntropyCache }) { + disableEntropyCache = !!disableEntropyCache; + bench.start(); + for (let i = 0; i < n; ++i) + randomUUID({ disableEntropyCache }); + bench.end(n); +} diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 2b762fa2eeef69..78dd5b74845dbb 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -3160,6 +3160,21 @@ const n = crypto.randomInt(1, 7); console.log(`The dice rolled: ${n}`); ``` +### `crypto.randomUUID([options])` + + +* `options` {Object} + * `disableEntropyCache` {boolean} By default, to improve performance, + Node.js will pre-emptively generate and persistently cache enough + random data to generate up to 128 random UUIDs. To generate a UUID + without using the cache, set `disableEntropyCache` to `true`. + **Defaults**: `false`. +* Returns: {string} + +Generates a random [RFC 4122][] Version 4 UUID. + ### `crypto.scrypt(password, salt, keylen[, options], callback)`