CardShuffle.py

From Werner KRAUTH

Jump to: navigation, search
import random,pylab
n = 3
data = []
HistoData = {}
for iter1 in range(100000):
    L = list(range(n))
    green_card = n - 1
    for iter2 in range(200000):
        a = L.pop(0)
        L.insert(random.randint(0, n - 1), a)
        if a == green_card:
            LL = tuple(L)
            if LL in HistoData: HistoData[LL] += 1
            else: HistoData[LL] = 1
            data.append(iter2)
            break
print(HistoData)
pylab.hist(data,bins=20,normed=True)
pylab.savefig('Histo_shuffle.png')
pylab.show()
Personal tools