AS3 Shuffle Array

Submitted by:Jhon Jhon

Date added:06 June, 2011

Category:ActionScript 3

This reorders the elements of an array into a random order.

Tags: shuffle array

Code Snippet:

var anArray:Array = [1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4];
anArray=shuffleArray(anArray);

function shuffleArray(arr:Array):Array{
var arr2:Array = [];
while (arr.length > 0){
arr2.push(gendersArray.splice(Math.round(Math.random() * (arr.length - 1)), 1)[0]);
}
return arr2;
}
 
 

Comments