-
-
Save pc035860/6546661 to your computer and use it in GitHub Desktop.
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
function randInt(min,max){ | |
var range = max - min; | |
// it actually does work the other way... | |
// if (range < 0) { throw new RangeError("min must be less than max"); } | |
var rand = Math.floor(Math.random() * (range + 1)); | |
return min + rand; | |
} |
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
function randInt(a,b){return a+Math.floor(Math.random()*(++b-a))} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man! This works like a charm!