Created
February 3, 2012 00:10
-
-
Save phette23/1726649 to your computer and use it in GitHub Desktop.
Generate a random integer between any two values
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
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