发红包方法总结(持续更新.......
import random def red_packet(money,num): ret = random.sample(range(1,money*100),num-1) print(ret) ret.sort() ret.insert(0,0) print(len(ret)) ret.append(money*100) print(ret) for i in range(len(ret)-1): yield (ret[i+1] - ret[i])/100 ret_g = red_packet(200,10) # print(list(ret_g)) for money in ret_g: print(money) # import random # def func(s,n): # li = [] # for ii in range(n): # li.append(random.random()) # print(li) # ss= sum(li) # print(ss) # for i in range(n): # li[i]= float(format(s/ss*li[i],'0.2f')) # return li # print(func(100,5))