Eli Bendersky explains why the Fisher-Yates shuffling algorithm works:
What I do plan to do, however, is to explain why the Fisher-Yates algorithm works. To put it more formally, why given a good random-number generator, the Fisher-Yates shuffle produces a uniform shuffle of an array in which every permutation is equally likely. And my plan is not to prove the shuffle’s correctness mathematically, but rather to explain it intuitively. I personally find it much simpler to remember an algorithm once I understand the intuition behind it.
This is the algorithm that the Collections.shuffle()
method in Java uses.
Leave a Reply