Posted By

jaredyeo on 11/07/10


Tagged

array Randomize randomise


Versions (?)

Who likes this?

9 people have marked this snippet as a favorite

alptugan
sexyflash
CreativeAddiction
onemanstudio
tspitzr
weavermedia
prjohnny
kojok
mitien


AS3 Randomize Array


 / Published in: ActionScript 3
 

URL: http://simplistika.com

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

Report this snippet  

You need to login to post a comment.