if (max - min === Infinity) {
throw new RangeError('Invalid interval')
}
- return (crypto.randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min
+ return (randomBytes(4).readUInt32LE() / 0xffffffff) * (max - min) + min
}
/**
-import crypto from 'node:crypto'
+import { randomInt } from 'node:crypto'
import Benchmark from 'benny'
import {
secureRandom,
max = Math.floor(max)
if (min != null && min !== 0) {
min = Math.ceil(min)
- return Math.floor(crypto.randomInt(min, max + 1))
+ return Math.floor(randomInt(min, max + 1))
}
- return Math.floor(crypto.randomInt(max + 1))
+ return Math.floor(randomInt(max + 1))
}),
Benchmark.add('Math random integer generator', () => {
getRandomInteger(maximum)
-import crypto from 'node:crypto'
+import { randomUUID } from 'node:crypto'
import Benchmark from 'benny'
import { v4 as uuid } from 'uuid'
Benchmark.suite(
'UUIDv4 generator',
Benchmark.add('crypto randomUUID', () => {
- crypto.randomUUID()
+ randomUUID()
}),
Benchmark.add('uuid', () => {
uuid()