要求如下:文章来源:https://www.toymoban.com/news/detail-847504.html
#1.红包的总金额total,发放红包的数量num
#2.每个红包的最低金额为1元,且每个红包均为整数金额
#每个红包的金额【总金额-已抢红包*1】文章来源地址https://www.toymoban.com/news/detail-847504.html
import random
def get_random_red_packet(total_amount, people_count):
already = 0
for i in range(people_count-1):
left = total_amount - already - 1 # everyone should more than 1yuan
max_per_people = left / (people_count-i) * 2
packet = random.randint(1, max_per_people)
print('%s:%s' % (i, packet))
already += packet
print('%s:%s' % (people_count-1, total_amount - already))
if __name__ == '__main__':
get_random_red_packet(100, 10)
get_random_red_packet(1000, 20)
到了这里,关于python3抢红包的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!