Skip to content

Instantly share code, notes, and snippets.

@rike422
Created December 16, 2014 05:06
Show Gist options
  • Save rike422/6d567a6c2c4978257d8b to your computer and use it in GitHub Desktop.
Save rike422/6d567a6c2c4978257d8b to your computer and use it in GitHub Desktop.
Array.sample
Array.prototype.sample = function(loop) {
var result = [], loop = loop || 1;
for(var i = 0; i < loop; i++) {
result.push(this[Math.floor(Math.random() * this.length)]);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment