So let's say I have a list of numbers (not a specific range, which could change), and want to generate a random number which excludes the numbers in the list.
List of excluded numbers comes from a sql query.
and the only limit for the random number is the number of digits, which can come from:
random_number = ''.join(random.choice(chars) for _ in range(size))
so I want to generate the random number (with size limit) excluding a list of numbers.
while random_number in exclude_list:
random_number = ''.join(random.choice(string.digits) for _ in range(size))
Is there a pythonic way (other than using while loop) to do that?
example: generate a 2digit random number which does not exist in a list of numbers like exclude_list=[22,34,56,78]