Programming: Fisher-Yates Shuffle

I spent a portion of my weekend writing a card game in Java.  Part of the effort required me to to shuffle a deck of cards.  I rolled my own solution for this, which to me, personally, is part of the fun – (why? related to this article ).  I did learn, however, that, like many things, there are well documented solutions for such things.  Ergo, the Fisher-Yates Shuffle algorithm and its offsprings.

The cool thing about the Fisher-Yates is its efficiency in processing.  This is achieved by diminishing the array size while iterating through and drawing out values.  The smaller the heap, the faster it gets.

If you are interested in learning more about Fisher-Yates, here is a nice Wikipedia entry on the algorithm.

Leave a Reply

Your email address will not be published.