[问题] 请问不重复乱数的逻辑思考

楼主: FunkyBass (假放克)   2015-03-20 15:05:47
程式码如下:
var random = new Array();
random[0] = Math.floor(Math.random()*10);
random[1] = Math.floor(Math.random()*10);
random[2] = Math.floor(Math.random()*10);
random[3] = Math.floor(Math.random()*10);
random[4] = Math.floor(Math.random()*10);
random[5] = Math.floor(Math.random()*10);
random[6] = Math.floor(Math.random()*10);
random[7] = Math.floor(Math.random()*10);
random[8] = Math.floor(Math.random()*10);
random[9] = Math.floor(Math.random()*10);
for(var i = 0 ; i < 10 ; i++){
if(random[i] == random[i+1]){
random[i+1] = Math.floor(Math.random()*10);
i
作者: mmis1000 (秋月恋枫)   2015-03-20 15:22:00
http://jsbin.com/liyaso先把要出现的数字选出来在洗牌阿
作者: swallowcc (guest)   2015-03-20 16:15:00
把值塞进array里再shuffle...大概像这样 http://goo.gl/6xayg
楼主: FunkyBass (假放克)   2015-03-20 16:27:00
谢谢两位大大,已解决,洗牌这事情比我原先想的好太多

Links booklink

Contact Us: admin [ a t ] ucptt.com