oh the randomness
Posted By Thaylin on May 14, 2008
1 2 3 4 5 6 7 8 9 10 | 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.
Comments
Leave a Reply
Please note: Comment moderation is currently enabled so there will be a delay between when you post your comment and when it shows up. Patience is a virtue; there is no need to re-submit your comment.