def get_number(size):
    l = [str(i) for i in list(range(10))]
while l[0] == '0':
    random.shuffle(l)
return int(''.join(l[:size]))
How to generate effectively a random number that only contains unique digits in Python?