大转盘抽奖概率 固定每个区域的中奖几率
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))
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了