Shuffling a deck of cards is a basic coding interview question, but I prefer a more interesting version. How do you code a simulation of real-life shuffling? Take a basic riffle. Cut the cards roughly in half and interleave the cards. Of course if they are perfectly interleaved then the arrangement is not random, so that's not what happens. In reality there's a "clumping factor" that causes a few cards to stick together on each side. What other variables are at play? Can you reproduce the finding that it takes seven shuffles to fully randomize a deck?
> Then, one card at a time is repeatedly moved from the bottom of one of the packets to the top of the shuffled deck, such that if x cards remain in one packet and y cards remain in the other packet, then the probability of choosing a card from the first packet is x/(x + y) and the probability of choosing a card from the second packet is y/(x + y).