0

So I am pretty new to Python and to coding in general and I am trying to make a random number generator which makes a list of what numbers havent been displayed yet and doesnt repeat any of the numbers that have been displayed.

Thanks if someone wants to help me with this!

code:

random.randrange(1, 50, 1) for i in range(7)

print ("number list is : " + str(res))

1 Answers1

0
import random

lst = []

while len(lst) < 49:

    res = random.randrange(1, 50, 1)

    if res not in lst:

        print ("number list is : " + str(res))
        lst.append(res)

Here, you create a list lst and set your code in a while loop which focus on the length of lst. As the max of different number you can get is 49, you will stop getting random number once this condition is reached.

If your number res is not in lst, you print and append res to lst. If it is in lst, you just don't mention anything and loop again to the next "new" number.

Synthase
  • 5,849
  • 2
  • 12
  • 34