Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Javascript — random number in a specific range

View random.js
1 2 3 4 5 6 7 8 9 10 11
// MIT License
 
// @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);
}

Thanks for this - it came in useful and helped me solve a problem today. :grinning:

Owner

Always welcome! Glad to know that it's helpful. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.