def gencoordinates(m, n):
    seen = set()
x, y = randint(m, n), randint(m, n)
while True:
    seen.add((x, y))
yield x, y
x, y = randint(m, n), randint(m, n)
while (x, y) in seen:
    x, y = randint(m, n), randint(m, n)
How to generate random pairs of numbers in Python, including pairs with one entry being the same and excluding pairs with both entries being the same?