Unique Random Array


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

Just uses the sort function to randomize an array


Copy this code and paste it in your HTML
  1. var originalArray:Array = new Array("alpha", "bravo", "charlie", "delta", "echo", "foxtrot");
  2. var shuffledArray:Array = originalArray.sort(shuffle);
  3. trace(shuffledArray);
  4.  
  5. function shuffle(originalArray,shuffledArray):int
  6. {
  7. var sortNum : int = Math.round(Math.random() * 2) - 1;
  8. return sortNum;
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.