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

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,[]));
}

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

你可能感兴趣的:(web前端)