Hi everyone,
I was creating something that needed a function for shuffling the contents of an array. In case it is helpful, here it is:
public function Main() {
// constructor code
var tempArray:Array = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
trace("original: " + tempArray);
ShuffleArray(tempArray);
trace("new: " + tempArray);
}
public function ShuffleArray(input:Array)
{
for (var i:int = 0; i < input.length; i++)
{
var randomIndex:int = Math.floor(Math.random()*input.length);
var tempValue = input[randomIndex];
input[randomIndex] = input*;
input* = tempValue;
}
}
}
I’ll probably write a tutorial on this later, so feel free to let me know if there is a quicker/faster way of doing this.
:beam: