Public
Authored by DuWenHe

自定义概率抽取

Edited

choice()方法可以对列表[1,2,2,3]抽取,结果及概率分别是1-25%,2-50%,3-25%; 好奇网络游戏抽奖概率是怎么设置的(因为感觉有些装备的概率像0.000001), 这样的概率用choice()实现非常浪费内存,因为要开辟一个很大的列表,后来找到了一种较好的方法可以实现自定义概率抽取,节省时间更节省空间!

这个小技巧是从《Think Python Like A Computer Scientist》上学到的。

UpdatedChoice.py 1 KB
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment