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 fb4d7977b17ff8..5ae5ad6b7a99ee 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -2841,6 +2841,20 @@ 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 generates and caches 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)`