def newshuffle(x):

    def _randbelow(n):
        """Return a random int in the range [0,n).  Raises ValueError if n==0."""
getrandbits = random.getrandbits
k = n.bit_length()
r = getrandbits(k)
while r >= n:
    r = getrandbits(k)
return r
for i in range(len(x) - 1, 0, -1):
    j = _randbelow(i + 1)
x[i], x[j] = x[j], x[i]
Difference between Python 2 and 3 for shuffle with a given seed