从数组中随机获得1个子集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
var i, j:uint; var arr1:Array = new Array(1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"); var arr2:Array = new Array(); var len:uint = arr1.length; for (i = 0; i < len; i ++) { if (arr2.length < 6) { j = Math.floor(Math.random() * arr1.length); arr2.push(arr1.splice(j,1)); } else { break; } trace(i) } trace(arr1) trace(arr2) |