Skip to content

Instantly share code, notes, and snippets.

@shaneriley
Created April 4, 2012 14:50
Show Gist options
  • Save shaneriley/2302099 to your computer and use it in GitHub Desktop.
Save shaneriley/2302099 to your computer and use it in GitHub Desktop.
$.random(*number)
(function($) {
$.fn.random = function(qty) {
var $pool = this,
$picks = $(),
$e;
qty = qty || 1;
while (qty) {
$e = $pool.eq(~~(Math.random() * $pool.length));
$picks = $picks.add($e);
$pool = $pool.not($e);
qty--;
}
return $picks;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment