随机数,想求不重复,输出随机范围所有数字
public function Main():void { var arr:Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; var ranArr:Array = []; var k:int; var b:Boolean = true; while (b) { k = Math.random() * (arr.length); if (ranArr.indexOf(arr[k]) == -1) {trace("插入" + arr[k])ranArr.push(arr[k]); } if (ranArr.length == 10) { b = false; } } trace(ranArr.length); for (var i:int = 0; i < ranArr.length; i++ ) {trace(ranArr[i]); } }
while(b){ i = Math.random() * cardArr.length; cardArr.push(cardArr.splice(i,1)[0]); count++; if(count==500) b= false; }