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

首頁 > 編程 > Python > 正文

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

2019-11-25 16:25:54
字體:
來源:轉載
供稿:網友

實例如下:

</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 實現紅包隨機生成算法的簡單實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东源县| 习水县| 茶陵县| 玉龙| 丰原市| 鸡泽县| 漠河县| 克什克腾旗| 资中县| 石柱| 天峨县| 大庆市| 高碑店市| 施甸县| 卢湾区| 冷水江市| 芷江| 海宁市| 津市市| 洞口县| 富蕴县| 峨边| 宜川县| 积石山| 遵义县| 嫩江县| 东兴市| 五大连池市| 珲春市| 克拉玛依市| 邵阳市| 确山县| 芷江| 靖远县| 合阳县| 靖西县| 抚顺县| 阆中市| 乌海市| 沙洋县| 石屏县|