return byteLength
}
-export function bigintRandom (max: bigint = 0xFFFFFFFFFFFFFFFFn): bigint {
- if (typeof max !== 'bigint' || max < 1n) {
- throw new TypeError('Invalid max value')
- }
- const randomUint8Array = new Uint8Array(bigintByteLength(max))
- const mask = (1n << bigintBitLength(max)) - 1n
+export function bigintRandom (): bigint {
+ const mask = 0xFFFFFFFFFFFFFFFFn
+ const randomUint8Array = new Uint8Array(8)
let output = 0n
do {
output = 0n
output += BigInt(randomUint8Array[i])
}
output &= mask
- } while (output > max)
+ } while (output > mask)
return output
}