import random


def random_pair(n, min_dist=1, index1=None):
    """ Return a random pair of integers in the range [0, n) with a minimum distance between them.

    Args:
        n (int): Determine the range size
        min_dist (int): The minimum distance between the random pair
        index1 (int, optional): If specified, this will determine the first integer

    Returns:
        (int, int): The random pair of integers.
    """
    r1 = random.randint(0, n - 1) if index1 is None else index1
    d_left = min(r1, min_dist)
    d_right = min(n - 1 - r1, min_dist)
    r2 = random.randint(0, n - 2 - d_left - d_right)
    r2 = r2 + d_left + 1 + d_right if r2 >= (r1 - d_left) else r2

    return r1, r2