Skip to content

Instantly share code, notes, and snippets.

@bondarewicz
Last active December 15, 2015 19:19
Show Gist options
  • Select an option

  • Save bondarewicz/5310944 to your computer and use it in GitHub Desktop.

Select an option

Save bondarewicz/5310944 to your computer and use it in GitHub Desktop.
JS: Returns a random number between min and max
/**
* Returns a random number between min and max
* @param min in range [default 1]
* @param max in range [default 100]
* @dec decimal places for result [default 2]
*
* @return float
*/
function getRandomArbitary (min, max, dec) {
dec = typeof dec !== 'undefined' ? dec : 2;
min = typeof min !== 'undefined' ? min : 1;
max = typeof max !== 'undefined' ? max : 100;
return parseFloat((Math.random() * (max - min) + min).toFixed(dec));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment