Sunday, March 18, 2018 03:41 am EDT


Bri's picture

Randomly Shuffle an Array Using ActionScript 3

If you have ever wanted to randomly re-arrange the elements of an array after they are already set, try using this function.

function randomizeArray(array:Array):Array
var newArray:Array = new Array();
while(array.length > 0){
var randomIndex = Math.floor(Math.random()*array.length);
array.splice(randomIndex, 1)
return newArray;

The function takes in the array that you want to be modified and returns a new one.

Syndicate content