Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Javascript — random number in a specific range
// 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:


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.