Created
August 17, 2015 09:22
-
-
Save Dzinlife/61f1f9d87042bceac897 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 randomArray(array){ | |
function swap(obj, a, b) { | |
var tmp = obj[a]; | |
obj[a] = obj[b]; | |
obj[b] = tmp; | |
} | |
var length = array.length; | |
var rand = function(){ | |
return Math.round(Math.random() * (length - 1)); | |
} | |
for(var n in array){ | |
swap(array, n, rand() % (n + 1)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment