Shuffle an array

The general method for shuffling is biased. Check this – and

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 –


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s