随机不重复数组内容


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



Copy this code and paste it in your HTML
  1. var _arr:Array = new Array(1,3,5,7,9,32,43,45);
  2. var _length = _arr.length;
  3. for (var i = 0; i < _length; i++) {
  4. var rnd = Math.floor(Math.random() * _arr.length);//对应数组的key
  5. trace(_arr[rnd]);
  6. _arr.splice(rnd, 1);
  7. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.