Skip to content

Instantly share code, notes, and snippets.

@EmanuelCampos
Created September 14, 2021 11:52
Show Gist options
  • Save EmanuelCampos/5f06b7fe6b31c3f26794747d112ed0e2 to your computer and use it in GitHub Desktop.
Save EmanuelCampos/5f06b7fe6b31c3f26794747d112ed0e2 to your computer and use it in GitHub Desktop.
Generate Random BigNumber
const BigNumber = require("bignumber.js");
BigNumber.config({
DECIMAL_PLACES: 1,
ROUNDING_MODE: BigNumber.ROUND_FLOOR
});
function generateRandomNrBetween(min, max) {
return BigNumber.random(1)
.times(max - min)
.plus(new BigNumber(min));
}
console.log(generateRandomNrBetween(20, 210).toFixed());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment