国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 實現紅包隨機生成算法的簡單實例

2020-02-23 04:12:23
字體:
來源:轉載
供稿:網友

實例如下:

</pre><pre name="code" class="python">#! /usr/bin/python# -*- coding: utf-8 -*-import randomclass CDispatch: def __init__(self,sum,count):  self.sum = sum  self.count=count  #print 'init here sum =',sum,',count =',count def __del__(self):  pass  #print 'run del the class' def getListInfo(self):  listInfo=[]  sumMoney = self.sum*100    for num in range(0,self.count):   if(num == self.count -1):    listInfo.append(float('%0.2f'%sumMoney)/100)    break   bigRand=sumMoney+1+num-self.count   #print 'sumMoney=',sumMoney,'num=',num,'self.count=',self.count,'big=',bigRand   try:    a = random.randint(1,int(bigRand))   except:    for i in range(0,num):     print 'listInfo[%d]'%i,'=',listInfo[i]    if num >0:     print 'sumMoney=',sumMoney,'num=',num,'listInfo[num-1]=',listInfo[num-1],'self.count=',self.count,'big=',bigRand   #print 'a=',a    break   sumMoney -=a   listInfo.append(float(a)/100)     return listInfofor i in range(0,100000): dispatch = CDispatch(1.05,5) listGet = dispatch.getListInfo() print listGet del dispatch

以上這篇python 實現紅包隨機生成算法的簡單實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江华| 龙门县| 淮阳县| 景德镇市| 溧阳市| 新源县| 凤山市| 长寿区| 手游| 乌苏市| 临沧市| 白山市| 休宁县| 新兴县| 沂水县| 濮阳市| 东辽县| 鹤峰县| 宁城县| 拉萨市| 积石山| 大连市| 云南省| 新疆| 册亨县| 崇信县| 延庆县| 嘉定区| 萝北县| 德清县| 舒城县| 新竹市| 道孚县| 依兰县| 东源县| 淮安市| 阿拉善左旗| 怀来县| 六安市| 满城县| 桃园县|