(彩票)随机数中奖概率

function random(min, max) {
    if (!max) {
        [min, max] = [0, min];
    }
    let number = parseInt(Math.random() * (max - min + 1) + min);
    return number;
}
function ball() {
    let s = new Set();
    while (s.size < 6) {
        s.add(random(1, 33));
    }
    let red = [...s].sort((a, b) => a - b);  // 红球
    let blue = random(1, 16);      // 蓝球

    let s_blue = new Set();
    while (s_blue.size < 6) {
        s_blue.add(random(1, 33));
    }
    let red_blue = [...s_blue].sort((a, b) => a - b);  // 红球1
    let blue_blue = random(1, 16);      // 蓝球1

    let intersection = new Set(red.concat(red_blue)); // Set吧两个数组装起来 判断长度来来执行有多少重复
    if (intersection.size == 6 && blue == blue_blue) {
        console.log('恭喜你一等奖');
    } else if (intersection.size == 6) {
        console.log('恭喜二等奖');
    } else if (intersection.size == 7 && blue == blue_blue) {
        console.log('恭喜三等奖');
    } else if (intersection.size == 7 || intersection.size == 4 && blue_blue == blue) {
        console.log('恭喜四等奖');
    } else if (intersection.size == 8 || intersection.size == 9 && blue == blue_blue) {
        console.log('恭喜五等奖');
    } else if (intersection.size == 10 && blue == blue_blue || intersection.size == 11 && blue_blue == blue || intersection.size == 12 && blue_blue == blue) {
        console.log('恭喜六等奖');
    } else {
        console.log('很遗憾你没有中奖');
    }
}
ball();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值