Algorithm to Shuffle a Deck of Cards

Write an algorithm to shuffle an array of 52 integers so that each number has equal probability to be in any of the 52 positions.

2 Comments

  1. techie007 says:

    Knuth Shuffle / Fisher–Yates shuffle / Durstenfeld implementation
    The modern version of the Fisher–Yates shuffle, designed for computer use, was introduced by Richard Durstenfeld in 1964 in Communications of the ACM volume 7, issue 7, as “Algorithm 235: Random permutation”The algorithm thus becomes, for a set of N elements:

    1. Let A1 := 1, A2 := 2 and so on up to AN := N, and let n := N.
    2. Pick a random number k between 1 and n inclusive.
    3. Swap the values of Ak and An.
    4. Decrease n by one.
    5. Repeat from step 2 until n is less than 2.

    http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

  2. HECTOR says:


    CheapTabletsOnline.Com. Canadian Health&Care.Best quality drugs.No prescription online pharmacy.Special Internet Prices. Low price pills. Order pills online

    Buy:Cialis Professional.Cialis Soft Tabs.Viagra.Super Active ED Pack.Tramadol.Propecia.Viagra Super Force.Viagra Soft Tabs.Levitra.Soma.Cialis.VPXL.Viagra Professional.Zithromax.Viagra Super Active+.Cialis Super Active+.Maxaman….

Leave a Reply