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();
(彩票)随机数中奖概率
最新推荐文章于 2024-09-06 22:20:29 发布