大转盘抽奖概率 固定每个区域的中奖几率


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))
复制代码

 

posted on   星河赵  阅读(1912)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示