# 用python实现的两种抽奖算法以及基于tkinter实现的简单GUI(概率随机抽奖、次数随机算法)

------------次数随机算法----------

#抽奖一次少一个名额

class randomMachine(object):
import random as rd
def setWeight(self, weight):
self.weight = weight
self.chanceList=[]
for k,v in self.weight.items():
for t in range(v):
self.chanceList.append(k)

def drawing(self):
r = self.rd.randrange(0, len(self.chanceList))  # 随机数
#print("随机数 : ", r)

print(self.chanceList.pop(r))

def graphicsUI(self):
pass

def start(self):
pass

if __name__ == "__main__":
test = randomMachine()
test.setWeight({"一等奖": 1, "二等奖": 1, "三等奖": 1, "安慰奖": 6})
for i in range(9):
test.drawing()

---------概率随机算法----------

class randomMachine(object):
import random as rd
def setWeight(self, weight):
self.weight = weight
WEIGHT = {}
weightLength = len(self.weight)  # 权重个数
valueCount = 0  # 权重合计
for v in self.weight.values():
valueCount += v

• 0
点赞
• 11
收藏
觉得还不错? 一键收藏
• 2
评论
04-03
02-28
06-05 189
09-17 1630
06-21 4452

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。