Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Make a ReactNative component take the height and width of the current window 
Javascript :: Replacing Specific word from url, replacing url 
Javascript :: get image height Jimp nodejs 
Javascript :: poo javascript heritage 
Javascript :: fetch image from cloudinary in nodejs 
Javascript :: nvm install a particular version 
Javascript :: how can i use two api at the same time in angular 
Javascript :: multiple comparison javascript 
Javascript :: moment iso string to zero 
Javascript :: forward slash in ajax url 
Javascript :: how to input struct into parameter in remix 
Javascript :: how get value of datePicker in react 
Javascript :: typeof regex 
Javascript :: Bitwise IndexOf Shorthand in javascript 
Javascript :: vs code javascript type check 
Javascript :: Node-Red: 2Outputs 
Javascript :: trigger many calls JavaScript 
Javascript :: convert online code javascript to python 
Javascript :: how to merge data react native 
Javascript :: discord.js v12 to v13 
Javascript :: javascript const scope = await angular.element(document.body).scope(); 
Javascript :: why typescript is superset of javascript 
Javascript :: Private slots are new and can be created via Static initialisation blocks in classes 
Javascript :: disabling first item in dropdownlist 
Javascript :: change teh value of a slider p5js 
Javascript :: material ui refresh icon 
Javascript :: js uid from 8 characters or digits 
Javascript :: default parameters in es6 
Javascript :: Imports should be sorted alphabetically sort-imports 
Javascript :: js hello 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =