Last active
December 15, 2015 19:19
-
-
Save bondarewicz/5310944 to your computer and use it in GitHub Desktop.
JS: Returns a random number between min and max
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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