Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bigInt.rand = function (bitLength) {
let bytes = bitLength / 8;
let buf = Buffer.alloc(bytes);
crypto.randomFillSync(buf);
buf[0] = buf[0] | 128; // first bit to 1 -> to get the necessary bitLength
return bigInt.fromArray([...buf], 256);
};