大转盘抽奖概率 固定每个区域的中奖几率
生活随笔
收集整理的這篇文章主要介紹了
大转盘抽奖概率 固定每个区域的中奖几率
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
get_double_reward_index 完整算法復制運用即可
原理一共是100份落到每一份概率相等,循環次數越多抽獎越是準確
def get_double_reward_index(rate_conf):
"""
抽獎概率計算
rate_conf = [[0.25, ''], [0.05, 129600], [0.01, 777600], [0.35, ''], [0.2, ''], [0.14, 10]]
return 獎勵index
"""
start, index = 0, 0
rate = [i[0] for i in rate_conf]
randnum = random.uniform(0, sum(rate))
for index, scope in enumerate(rate):
start += scope
if randnum <= start:
break
return index
l1 = [[0.25, ''], [0.05, 129600], [0.01, 777600], [0.35, ''], [0.2, ''], [0.14, 10]]
c = get_double_reward_index(l1)
total, i0, i1, i2, i3, i4, i5 = 0, 0, 0, 0, 0, 0, 0
for i in range(1000000):
index = get_double_reward_index(rate_conf=l1)
total += 1
if index == 0:
i0 += 1
elif index == 1:
i1 += 1
elif index == 2:
i2 += 1
elif index == 3:
i3 += 1
elif index == 4:
i4 += 1
elif index == 5:
i5 += 1
print("index 0 概率 %f" % ((i0 / total) * 100))
print("index 1 概率 %f" % ((i1 / total) * 100))
print("index 2 概率 %f" % ((i2 / total) * 100))
print("index 3 概率 %f" % ((i3 / total) * 100))
print("index 4 概率 %f" % ((i4 / total) * 100))
print("index 5 概率 %f" % ((i5 / total) * 100))
總結
以上是生活随笔為你收集整理的大转盘抽奖概率 固定每个区域的中奖几率的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IEEE 期刊缩写大全列表
- 下一篇: 实时操作系统的概念