Skip to content

Instantly share code, notes, and snippets.

@msenkpiel
Created February 6, 2012 14:18
Show Gist options
  • Save msenkpiel/1752333 to your computer and use it in GitHub Desktop.
Save msenkpiel/1752333 to your computer and use it in GitHub Desktop.
simple function that returns a random number between a expected range
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