Skip to content

Instantly share code, notes, and snippets.

@Dzinlife
Created August 17, 2015 09:22
Show Gist options
  • Save Dzinlife/61f1f9d87042bceac897 to your computer and use it in GitHub Desktop.
Save Dzinlife/61f1f9d87042bceac897 to your computer and use it in GitHub Desktop.
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