Jan-05-2020, 04:44 PM
Thanks a lot all for your help, random.sample did the trick.
My code went from this:
My code went from this:
import random lottorad = [0, 0, 0, 0, 0, 0, 0] unik_rad = False while unik_rad == False: for x in range(0, 7): lottorad[x] = random.randint(1, 34) # lottoraden är nu fylld med 7 nummer. # kontrollerar om samtliga nummer i lottoraden är unika for x in range(1, 35): lika = lottorad.count(x) if lika > 1: # minst två lika nummer har hittats unik_rad = False break else: unik_rad = True lottorad.sort() print(lottorad)to this:
import random lottorad = [] lottorad = random.sample(range(1, 34), 7) lottorad.sort() print(lottorad)Thanks again, problem solved