#72002/8/28 12:05:19
代码:
------------------------------------------------------------------------------
function randomNumbers(max_num, count) {
k = 0;
//避免数目大于最大取值范围
if (count>max_num) {
count = max_num;
}
random_num = new Array();
while (k //取得随机整数。
random_num[k] = Math.floor(Math.random()*max_num);
k++;
for (i=0; i //判断该数在数组中是否存在
if (random_num[i] == random_num[k-1]) {
trace("重复,再执行!");
//如果该数在数组中已存在,就再多算一次
k--;
break;
}
}
}
return random_num;
}
a = randomNumbers(10, 9);
trace(a);
------------------------------------------------------------------------------------------------
请看trace结果:
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
重复,再执行!
6,7,3,4,2,8,9,1,0
---------------------------------------------
一共执行了16次!
^_^