Math, asked by harshsahu4106, 1 year ago

Given 52 cards of deck, write a method to shuffle them and produce a permutation of cards such that every call to ts method will produce a distinct permutation.

Answers

Answered by himanshusingh52
3
If you swap the top card with a card chosen randomly with uniform distribution (including the card itself, in which case the "swap" doesn't change anything), then the new top card is any one of the cards with equal probability. Thus every card also has the same probability of not being that card, that is, of being in the subdeck below the top card. Thus the deck will be properly shuffled if the rest of the procedure properly shuffles that subdeck. But the rest of the procedure is precisely the whole procedure applied to that subdeck, so the result follows by induction, the base case being a deck of 11 card, which is always properly shuffled.

For the second part of the question, as Lopsy wrote, you'd have to say more about what you mean by "randomly swapping cards around".

Similar questions