I have found this tutorial:
construct.net/en/tutorials/implementing-fisher-yates-290
It works fine in itself. However, I cannot reuse it in a function. Can you make it work inside a function so that i could reuse it?
I tried passing the array with a array.uid, but it still does not work.
BTW, this is a javascript Fisher Yates, which works fine.
var array= [1,2,3];
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
var x=shuffleArray(array);
alert(x);
I would expect something like this to work each time I click the button: