Created
December 5, 2012 01:00
-
-
Save kaw2k/4210929 to your computer and use it in GitHub Desktop.
A simple extension of the javascript Number class for ease of generating random numbers.
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
// Example use | |
// var arr = [1, 2, 3, 4, 5]; | |
// var len = arr.length; | |
// var item = arr[len.random()]; | |
Number.prototype.random = function(inc) { | |
var val = (inc) ? 1 : 0; | |
return Math.floor(Math.random() * (this.valueOf() + val)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment