Last active
December 14, 2015 00:19
-
-
Save timohausmann/4997906 to your computer and use it in GitHub Desktop.
Javascript Math: get random number within boundaries
This file contains 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
/** | |
* return a random number within given boundaries. | |
* | |
* @param {number} min the lowest possible number | |
* @param {number} max the highest possible number | |
* @param {boolean} round if true, return integer | |
* @return {number} a random number | |
*/ | |
Math.randMinMax = function(min, max, round) { | |
var val = min + (Math.random() * (max - min)); | |
if( round ) val = Math.round( val ); | |
return val; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment