python发红包实现
import random def lucky_money(n, amount): """ :param n: 红包个数 :param amount: 红包金额(以元为单位) :return: 生成器,n个红包的金额,以分为单位 """ lst = list(random.sample(range(1, amount*100), n-1)) lst.sort() return (y - x for x, y in (zip([0]+lst, lst+[amount*100]))) # 测试 if __name__ == '__main__': g = lucky_money(10, 2) for i in g: print(i)