Flash Quick Tip: How to randomize an Array

Posted in Flash | 2 Comments
I had to google this today so i though i would share it with you! This snippet of actionscript can be used to simply re-order or randomize an array in Adobe Flash.
var myArray = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
myArray.sort(function (){
return Math.round(Math.random());
});
trace(myArray);
ps and yes i know I’ve spelt randomise wrong ; )
Spread me about thin:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis

You might also like:

2 Responses to “Flash Quick Tip: How to randomize an Array”

  1. praphul garg Says:

    on running the function the fist element is always 5. Why?


  2. Si Says:

    i have just created a new movie clip to test this and i have not found that it always starts with 5. It works perfectly for me!


Leave a Reply