Created
December 31, 2013 19:14
-
-
Save gre/8201023 to your computer and use it in GitHub Desktop.
Returns 2 random different elements 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
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