def randperm(n):
 r = range(n)
 x = []
 while r:
  i = random.choice(r)
  x.append(i)
  r.remove(i)
 return x

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