python random_shuffle (经典洗牌程序)


               
               
                #!/usr/bin/env python
__author__ = "lynn lin"
from random import random
def random_shuffle(A):
    length = len(A)
    for i in range(0,length):
        randomi = int(random()*length)
        print randomi
        A,A[randomi] = A[randomi],A
    return A
if __name__ == '__main__':
    A = [1,2,3,4,5]
    B = random_shuffle(A)
    print B