Skip to content

Instantly share code, notes, and snippets.

@johnpolacek
Created December 3, 2012 19:28
Show Gist options
  • Save johnpolacek/4197322 to your computer and use it in GitHub Desktop.
Save johnpolacek/4197322 to your computer and use it in GitHub Desktop.
Get Random Array Item
var item = items[Math.floor(Math.random()*items.length)];
@samccone
Copy link

items[~~(Math.random()*items.length)]

or Array.prototype.random = function(){return this[~~(Math.random() * this.length)]}

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