Skip to content

Instantly share code, notes, and snippets.

@timohausmann
Last active December 14, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timohausmann/4997906 to your computer and use it in GitHub Desktop.
Save timohausmann/4997906 to your computer and use it in GitHub Desktop.
Javascript Math: get random number within boundaries
/**
* 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