]> git.codecow.com Git - nano-pow.git/commitdiff
Simplify bigint RNG since it is never called with arguments.
authorChris Duncan <chris@codecow.com>
Mon, 25 May 2026 08:49:32 +0000 (01:49 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 25 May 2026 08:49:32 +0000 (01:49 -0700)
src/utils/bigint.ts

index 8d12f490c3920faf87e2abcd1d3faad7cb1a217a..85b26ac95cb1cafa432fd17f9d458d5b24ee5d48 100644 (file)
@@ -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
 }