import random


def randperm(n):
    """Function returning a random permutation of range(n)."""
    r = list(range(n))
    x = []
    while r:
        i = random.choice(r)
        x.append(i)
        r.remove(i)
    return x