Say I have an array:
myList:Array = new Array();
myList = [1,2,3,4,5,6,7,8,9];
myRandomList:Array = new Array();
for (var i:uint = 0; i < myList; i++) {
The title says shuffle an array so if you are looking for an ideal shuffle you may want the Fisher–Yates algorithm that is unbiased.
So if you wanted to use/keep your original, you would initialize myRandomList
var myRandomList: Array = new Array( myList.length );
Then create a random number with the range say a
and then swap myRandomList[a]
with myRandomList[i]
where i is the current element.
// Random number
var a = Math.floor(Math.random() * myList.length);
// A swap
myRandomList[i] = myRandomList[a];
// put whatever is in index a in the ith position
myRandomList[a] = myList[i];
// restore whatever was in the ith position to index a