Python implementation of red envelope random generation algorithm __ algorithm

Source: Internet
Author: User
</pre><pre name= "code" class= "Python" >#! /usr/bin/python #-*-Coding:utf-8-*-Import Random class Cdispatch:def __init__ (self,sum,count): self.su 
        m = 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 ('%0. 2f '%summoney)/100 break bigrand=summoney+1+num-self.count #print ' summoney= ', Summ Oney, ' 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 listinfo to I in range (0,100000 ): dispatch = Cdispatch (1.05,5) Listget = Dispatch.getlistinfo () print Listget del Dispatch


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.