ActionScript 3 Random Value Generation Randomize An Array


Example

var alphabet:Array = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ];

for (var i:int=alphabet.length-1;i>0;i--) {
    var j:int=Math.floor(Math.random()*(i+1));
    var swap=alphabet[j];
    alphabet[j]=alphabet[i];
    alphabet[i]=swap;
}
trace(alphabet);    

Example output

B,Z,D,R,U,N,O,M,I,L,C,J,P,H,W,S,Q,E,K,T,F,V,X,Y,G,A

This method is known as Fisher-Yates array shuffle.