AS3 Randomize Array


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



Copy this code and paste it in your HTML
  1. function fRandomize(vArray : Array) : void
  2. {
  3. var i : int;
  4. var j : int;
  5.  
  6. for (i = 0; i < vArray.length - 1; i++)
  7. {
  8. j = i + Math.floor(Math.random() * (vArray.length - i));
  9. if (j != i)
  10. fSwap(vArray, i, j);
  11. }
  12. }
  13.  
  14. function fSwap(vArray : Array, i : uint, j : uint) : void
  15. {
  16. var t : *;
  17.  
  18. t = vArray[i];
  19. vArray[i] = vArray[j];
  20. vArray[j] = t;
  21. }

URL: http://simplistika.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.