Shuffle an Array


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. private function shuffleArray($array:Array):Array
  2. {
  3. var shuffledArray:Array = new Array();
  4.  
  5. while ($array.length > 0) {
  6. shuffledArray.push($array.splice(Math.round(Math.random() * ($array.length - 1)), 1)[0]);
  7. }
  8.  
  9. return shuffledArray;
  10. }

URL: http://flassari.is/2009/04/as3-array-shuffle/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.