Python仿微信红包算法

根据 钱数 和 红包个数 生成 随机金额 的红包

def redbags(money, num=10):
    import random
    choice = random.sample(range(1, money * 100), num - 1)
    choice.extend([0,money*100])
    choice.sort()
    return [(choice[i + 1] - choice[i]) / 100 for i in range(num)]

 源码来源:http://www.cnblogs.com/ipyanthony/p/9493789.html

posted @ 2018-08-22 01:59  右仆射卧龙  阅读(1903)  评论(0)    收藏  举报