Skip to content

Instantly share code, notes, and snippets.

@gre
Created December 31, 2013 19:14
Show Gist options
  • Save gre/8201023 to your computer and use it in GitHub Desktop.
Save gre/8201023 to your computer and use it in GitHub Desktop.
Returns 2 random different elements from an Array
function random2elements (array) {
var i = Math.floor(array.length*Math.random());
var j = Math.floor((array.length-1)*Math.random());
if (j >= i) j++;
return [array[i], array[j]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment