dimanche 26 juillet 2020

How to make a function with random numbers

Hi I am trying to create a function that will select 5 random numbers which will equal a total amount already given and put the 5 numbers in a list. When I pass a number through the function I get an error. I cant seem to get what Im doing wrong.

def num_lottery(total_num):
    the_set =[]
    n1 = random.randint(1, total_num)
    n2 = random.randint(1, total_num - n1)
    n4 = random.randint(1, total_num - (n1 + n2 + n3))
    n5 = total_num - (n1 + n2 + n3 + n4)
    the_set.append(n1, n2, n3, n4, n5)
    return the_set

It works when I pass through the total_num = 50000, but not when total_num = 5000. Any help is appreciated. Thanks




Aucun commentaire:

Enregistrer un commentaire