import random def sh1(l): ln = len(l) for i in range(ln): rand = random.randint(0, ln-1) l[i], l[rand] = l[rand], l[i] return l def sh2(l): ln = len(l) for i in range(ln): rand = random.randint(i, ln-1) l[i], l[rand] = l[rand], l[i] return l res1 = {} res2 = {} for i in xrange(10000): r1 = tuple(sh1(["a", "b", "c"])) r2 = tuple(sh2(["a", "b", "c"])) if r1 in res1: res1[r1] += 1 else: res1[r1] = 1 if r2 in res2: res2[r2] += 1 else: res2[r2] = 1 print res1 print res2
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question