Skip to content

Instantly share code, notes, and snippets.

@pc035860
Forked from gengkev/randInt.js
Created September 13, 2013 04:02
Show Gist options
  • Save pc035860/6546661 to your computer and use it in GitHub Desktop.
Save pc035860/6546661 to your computer and use it in GitHub Desktop.
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;
}
function randInt(a,b){return a+Math.floor(Math.random()*(++b-a))}
@GriffinSego
Copy link

Thanks man! This works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment