JS双色球大乐透随机号码方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_29843547/article/details/73741260

code:

/* 生成指定0~范围指定个数随机数*/
function randRangeNumberFromOne(randomBeforeLotteryArr, range, count, except) {
    var randomNumberSet = [];
    for (var r = 1; r <= range; r++) {
        if (r < 10) {
            r = "0" + r;
        }
        randomNumberSet.push(r.toString());
    }
    /* 胆拖会去掉已经选择的胆码*/
    if (except.length > 0) {
        except.forEach(function (e) {
            randomNumberSet.splice(randomNumberSet.indexOf(e), 1);
        });
    }
    while (randomBeforeLotteryArr.length < count) {
        var randomNum = randomNumberSet[parseInt(Math.random() * randomNumberSet.length+1, 10)-1];
        randomNumberSet.splice(randomNumberSet.indexOf(randomNum), 1);
        randomBeforeLotteryArr.push(randomNum);
    }
    return randomBeforeLotteryArr;
}

usage

for(var i=0;i<=272618;i++){
   console.log('随机第'+i+'次');
   var arr = randRangeNumberFromOne([],33,6,[]);
   console.log(arr);
   var count = 0;
   /*['03','06','16','23','26','30'].forEach(function(e){
        if(arr.indexOf(e)>-1){
            count++;
        }
   })
   if(count>=6){
      break;
   }*/
   console.log(randRangeNumberFromOne([],16,1,[]));
}

什么时候随机出一个一等奖呢

猜你喜欢

转载自blog.csdn.net/sinat_29843547/article/details/73741260