import random


def _random_derangement(n):
    """
    Return a tuple random derangement of (0, 1, 2, ..., n-1).
    """
    while True:
        v = list(range(n))
        for j in range(n - 1, -1, -1):
            p = random.randint(0, j)
            if v[p] == j:
                break
            else:
                v[j], v[p] = v[p], v[j]
        else:
            if v[0] != 0:
                return tuple(v)