Generate random number in range excluding some numbers

Try this:

from random import choice

print(choice([i for i in range(0,9) if i not in [2,5,7]]))

Leave a Comment