Horje
random bigint javascript Code Example
random bigint javascript
/** Generates BigInts between low (inclusive) and high (exclusive) */
function generateRandomBigInt(lowBigInt, highBigInt) {
  if (lowBigInt >= highBigInt) {
    throw new Error('lowBigInt must be smaller than highBigInt');
  }

  const difference = highBigInt - lowBigInt;
  const differenceLength = difference.toString().length;
  let multiplier = '';
  while (multiplier.length < differenceLength) {
    multiplier += Math.random()
      .toString()
      .split('.')[1];
  }
  multiplier = multiplier.slice(0, differenceLength);
  const divisor = '1' + '0'.repeat(differenceLength);

  const randomDifference = (difference * BigInt(multiplier)) / BigInt(divisor);

  return lowBigInt + randomDifference;
}




Javascript

Related
react native communicate with webview Code Example react native communicate with webview Code Example
howler.js play file Code Example howler.js play file Code Example
how to copy all the elements of an array except the last one in javascript Code Example how to copy all the elements of an array except the last one in javascript Code Example
javascript search after user stops typing Code Example javascript search after user stops typing Code Example
nodejs get param cli Code Example nodejs get param cli Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7