From: Chris Duncan Date: Mon, 25 May 2026 08:49:32 +0000 (-0700) Subject: Simplify bigint RNG since it is never called with arguments. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=99e763029355c1cc6c6b98e1c1bf413a9ac9c817;p=nano-pow.git Simplify bigint RNG since it is never called with arguments. --- diff --git a/src/utils/bigint.ts b/src/utils/bigint.ts index 8d12f49..85b26ac 100644 --- a/src/utils/bigint.ts +++ b/src/utils/bigint.ts @@ -19,12 +19,9 @@ export function bigintByteLength (int: bigint): number { 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 @@ -35,7 +32,7 @@ export function bigintRandom (max: bigint = 0xFFFFFFFFFFFFFFFFn): bigint { output += BigInt(randomUint8Array[i]) } output &= mask - } while (output > max) + } while (output > mask) return output }