I'm assuming that the random function can generate uniformly distributed
random numbers between 0 and n(excluding n), where n is an +ive integer.

def randperm( A ):
    for i in range(0, n):
        t = i+1 + random(, n - i-1 )
        swap(A[t], A[i])

note that the permutation is in-place.

Anil


On Sat, Jun 26, 2010 at 4:55 PM, sharad kumar <sharad20073...@gmail.com>wrote:

> Write a method to shufle the deck. The constraint is it has to be a perfect
> shuffle - in other words, every 52! permutations of the deck has to be
> equally like (given a completely random function which is theoretical of
> course)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to