def __init__(self, n):
        """
        Init a Permute object. Randomly generate a mapping, e.g. [0,1,2] -> [1,0,2]
        """
        m = list(range(n))
        for end in xrange(n - 1, 0, -1):
            r = random.randint(0, end)
            tmp = m[end]
            m[end] = m[r]
            m[r] = tmp
        self.mapping = m
def __init__ ( self , n ) : m = list ( range ( n ) ) for end in xrange ( n - 1 , 0 , - 1 ) : r = random . randint ( 0 , end ) tmp = m [ end ] m [ end ] = m [ r ] m [ r ] = tmp self . mapping = m
Init a Permute object. Randomly generate a mapping, e.g. [0,1,2] -> [1,0,2]