2 parents f510207 + 09088cd commit 2d360cdCopy full SHA for 2d360cd
1 file changed
other/Fischer-Yates_Shuffle.py
@@ -0,0 +1,20 @@
1
+'''
2
+The Fisher–Yates shuffle is an algorithm for generating a random permutation of a finite sequence.
3
+For more details visit
4
+wikipedia/Fischer-Yates-Shuffle.
5
6
+import random
7
+
8
+def FYshuffle(LIST):
9
+ for i in range(len(LIST)):
10
+ a = random.randint(0, len(LIST)-1)
11
+ b = random.randint(0, len(LIST)-1)
12
+ LIST[a], LIST[b] = LIST[b], LIST[a]
13
+ return LIST
14
15
+if __name__ == '__main__':
16
+ integers = [0,1,2,3,4,5,6,7]
17
+ strings = ['python', 'says', 'hello', '!']
18
+ print ('Fisher-Yates Shuffle:')
19
+ print ('List',integers, strings)
20
+ print ('FY Shuffle',FYshuffle(integers), FYshuffle(strings))
0 commit comments