Created
February 6, 2012 14:18
-
-
Save msenkpiel/1752333 to your computer and use it in GitHub Desktop.
simple function that returns a random number between a expected range
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 getRandom(min, max) { | |
if (min > max) { | |
return -1; | |
} | |
if (min == max) { | |
return min; | |
} | |
var r; | |
do { | |
r = Math.random(); | |
} | |
while (r == 1.0); | |
return min + parseInt(r * (max - min + 1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment