Posts

Random shuffle Algorithm in python

Image
Sample from a deck of cards, source: http://playingcards.wikidot.com/bicycle Motivation Recently I took the online course " Design of Computer Program " taught by professor Peter Norvig. The course is simply great for any one who want to level up his programming skills. In the first assignment Peter talked about random shuffle algorithm and how to write a correct one.  What's a random shuffle algorithm? Given a collection of objects, (list of user identifiers, a 52-card deck) the random shuffle algorithm should re-arrange the objects in a random way. The end result is a permutation of the objects in the collection, but the algorithm must guarantee that all permutations are equally likely to appear, put simply the algorithm should not be biased toward any particular set of permutations. Example Let C = ["A", "B", "C"] All possible permutation of C are ["ABC", "ACB", "BAC", &qu