remeda
Version:
A utility library for JavaScript and Typescript.
2 lines • 526 B
JavaScript
function e(e,r){if(r<e)throw RangeError(`randomBigInt: The range [${e.toString()},${r.toString()}] is empty.`);let i=r-e,{length:a}=i.toString(2),o=Math.ceil(a/8),s=BigInt(8-a%8);for(;;){let r=n(o),a=t(r)>>s;if(a<=i)return a+e}}function t(e){let t=0n;for(let n of e)t=(t<<8n)+BigInt(n);return t}function n(e){let t=new Uint8Array(e);if(typeof crypto>`u`)for(let n=0;n<e;n+=1)t[n]=Math.floor(Math.random()*256);else crypto.getRandomValues(t);return t}export{e as randomBigInt};
//# sourceMappingURL=randomBigInt-DUNpiGnT.js.map