public
Last active

Javascript — random number in a specific range

  • Download Gist
random.js
JavaScript
1 2 3 4 5 6 7 8 9
// @return [float] a random number between min and max
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
 
// @return [integer] a random int between min and max
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.