Shuffle an array

The general method for shuffling is biased. Check this – https://spin.atomicobject.com/2014/08/11/fisher-yates-shuffle-randomization-algorithm/ and http://www.i-programmer.info/programming/theory/2744-how-not-to-shuffle-the-kunth-fisher-yates-algorithm.html

When shuffling the maximum number of possible outcome can’t be more then n!( n is the number of items being shuffled). So if the algo generate more then n! possible outcome then the algo is biased.

The Knuth Fisher-Yates Algorithm produces unbiased shuffled outcome. It relies on the fact that the each item/element is only shuffled once unlike the general algo which shuffles an element multiple time.

Code – http://www.geeksforgeeks.org/shuffle-a-given-array/

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s