Last active
October 15, 2015 18:09
-
-
Save benjamingsmith/4e0337b7025b78f25df1 to your computer and use it in GitHub Desktop.
Choose a random item from an array
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
$.rand = function(arg) { | |
if ($.isArray(arg)) { | |
return arg[$.rand(arg.length)]; | |
} else if (typeof arg === "number") { | |
return Math.floor(Math.random() * arg); | |
} else { | |
return 4; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment