fix(core): round value in randomBigIntInRange

This commit is contained in:
alina 🌸 2024-06-27 23:44:06 +03:00
parent 82ab154f0f
commit 28b2efbb08
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -117,7 +117,7 @@ export function randomBigIntInRange(crypto: ICryptoProvider, max: bigint, min =
const interval = max - min const interval = max - min
if (interval < 0n) throw new Error('expected min < max') if (interval < 0n) throw new Error('expected min < max')
const byteSize = bigIntBitLength(interval) / 8 const byteSize = Math.ceil(bigIntBitLength(interval) / 8)
let result = randomBigInt(crypto, byteSize) let result = randomBigInt(crypto, byteSize)
while (result > interval) result -= interval while (result > interval) result -= interval