Shuffling Array in Flash

We often need to shuffle array in flash but flash is not having any in-built function to shuffle the array.
Here is code to shuffle the array in a simple manner.

Please convert smart quotes to normal quote before pasting the following code to flash

// Initinal Value of the Array
var aData:Array = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

trace(‘Before Shuffling : aData = {‘+aData+’}’);// Before Shuffling : aData = {1,2,3,4,5,6,7,8,9,10}

for (i=0; i<aData.length; i++) {

//This will fetch the value at random index and save it in nData
var nData:Array = aData.splice(randRange(0, aData.length-1), 1);

//This will store the nData value to end of the same array

trace(‘After Shuffling : aData = {‘+aData+’}’);// After Shuffling : aData = {5,6,1,3,7,10,2,9,8,4}

function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;