Please if you know how to solve this: I need to add nested lists, each list with randomly generated numbers, but within the same range. If I run my code like it is, it adds nested lists, each list with the correct length of 6 numbers, but the problem is that all numbers in the lists are identical! the output is like that:
[
[27, 2, 23, 12, 9, 2, 28, 31],
[27, 2, 23, 12, 9, 2, 28, 31],
[27, 2, 23, 12, 9, 2, 28, 31],
[27, 2, 23, 12, 9, 2, 28, 31]
]
How can I manage to generate new numbers each time I call the function in the for loop?
lottery_numbers = []
numbers_list = []
def num_generator():
for num in range(0, 2):
random_number = random.randint(1, 40)
numbers_list.append(random_number)
lottery_numbers.append(numbers_list)
for number in range(0, 4):
num_generator()
Aucun commentaire:
Enregistrer un commentaire