Given a finite set of N cards, what is the best way (algorithm) to shuffle the cards so I will have the best shuffled pack of cards with minimum steps to get maximum random permutations?
What is the best solution in minimum steps?
Given a finite set of N cards, what is the best way (algorithm) to shuffle the cards so I will have the best shuffled pack of cards with minimum steps to get maximum random permutations?
What is the best solution in minimum steps?
Use Fisher Yates algorithm. Many programming languages use variant of this algorithm to shuffle elements of finite set. This is the pseudo code of Fisher Yates algorithm (optimised version by Richard Durstenfeld):
This algorithm ensures uniform distribution. For
N
cards, there are N! shuffled combinations possible. Here any ofN!
permutations is equally likely to be returned. Time complexity isO(N)
.This is the classic (which I believe is provably the best, using the exact number of bits needed for len(x) factorial permutations):