Flash Quick Tip: How to randomize an Array

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 ; )

2 thoughts on “Flash Quick Tip: How to randomize an Array

  1. 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

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>