Skip to content

Instantly share code, notes, and snippets.

@phette23
Created February 3, 2012 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/1726649 to your computer and use it in GitHub Desktop.
Save phette23/1726649 to your computer and use it in GitHub Desktop.
Generate a random integer between any two values
var integerBetween = function(x, y) {
if ( typeof x !== "number" || typeof y !== "number") {
console.log('integerBetween cannot accept NaN values');
return false;
}
else {
var lowerBound = Math.floor(x);
var upperBound = Math.floor(y);
return Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment