无聊写了一个脚本,看看福彩大乐透的中奖几率如何
注:每次买10注 成本20¥
第一次运行结果:在224303次中奖 成本 224303*20=4486060 448万
第一次运行结果:在5708621次中奖 成本 5708621*20=114172420 1.1亿
这辈子还能不能中奖了/(ㄒoㄒ)/~~?
源码献给各位追梦人!!
"""
模拟大乐透开奖
"""
import numpy as np
# 模拟开奖
def lottery():
one_li = np.array(range(1, 36))
two_li = np.array(range(1, 13))
before_nums = np.random.choice(one_li, 5, replace=False)
after_nums = np.random.choice(two_li, 2, replace=False)
obj = sorted(before_nums)
obj.extend(sorted(after_nums))
return obj
# 模拟选号
def simulated_pick(bet_number=1):
"""
bet_number : 购买注数
"""
li = []
for i in range(bet_number):
one_li = np.array(range(1, 36))
two_li = np.array(range(1, 13))
before_nums = np.random.choice(one_li, 5, replace=False)
after_nums = np.random.choice(two_li, 2, replace=False)
obj = sorted(before_nums)
obj.extend(sorted(after_nums))
li.append(obj)
return li
# 模拟兑奖
def check(lottery_number, bet_li):
"""
lottery_number : 开奖号码
bet_li: 下注号码列表
"""
for i in bet_li:
if str(i) == str(lottery_number):
return i
def run():
counts = 0
while True:
print(f'---第{counts}次---')
# 模拟选号
simulateds = simulated_pick(10)
for nums, i in enumerate(simulateds):
print(f"第{nums + 1}注: {i[0]} {i[1]} {i[2]} {i[3]} {i[4]} {i[5]} {i[6]}")
# 模拟开奖
s = lottery()
print(f"开奖号码:{s[0]} {s[1]} {s[2]} {s[3]} {s[4]} {s[5]} {s[6]}")
# 查看是否中一等奖
r = check(s, simulateds)
if r:
print(f'恭喜中1000w大奖!:{r[0]} {r[1]} {r[2]} {r[3]} {r[4]} {r[5]} {r[6]}')
break
counts += 1
if __name__ == '__main__':
run()
最后祝大家好运,有兴趣的可以交个朋友wx:pyhill