oh the randomness

private function randomSort(a:*, b:*):Number
{
            return Math.random()>.5 ? -1 : 1;
}
private function myFunc():void
{
             var myArrayToSort = [1,2,3,4,5];
            myArrayToSort.sort(randomSort);
             trace(MY ARRAY SORTED IS '+myArrayToSort)
}

Awesome way to randomly sort an array.
I’m using this with the sliver movie to randomly place the clips in various positions so every time you watch the movie it’s different.
Pretty damned cool.


Posted

in

, ,

by

Tags:

Comments

Leave a Reply