Posted By

donnydonny on 02/11/12


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

letmein_xxi


ActionScript 3 - Shuffle (random no repetition)


 / Published in: ActionScript 3
 

Random generator with no repetiotion using ActionScript 3

  1. var baseArray:Array;
  2. var numToGet:int = 8;
  3.  
  4. function makeBaseArray(f_length:int):void
  5. {
  6. baseArray = new Array();
  7. for (var i:int = 0; i < f_length; i++)
  8. {
  9. baseArray.push(i);
  10. }
  11. }
  12.  
  13. function getRandomNoRepeat():Number
  14. {
  15. var index:int = Math.random() * baseArray.length;
  16. var value:int = baseArray.splice(index,1)[0];
  17. return value;
  18. }
  19.  
  20. makeBaseArray(16);
  21.  
  22. for (var i:int = 0; i < numToGet; i++)
  23. {
  24. trace(getRandomNoRepeat());
  25. }

Report this snippet  

You need to login to post a comment.