
Fisher-Yates Shuffle
The Fisher-Yates shuffle is an efficient way to randomly rearrange a list of items, such as cards or numbers. It works by starting at the last item and swapping it with any item chosen randomly from the beginning up to that position. Then, it moves to the second-to-last item and repeats the process, swapping it with a randomly selected item from the remaining unshuffled part. This continues until all items have been processed, resulting in a thoroughly randomized order. The method ensures each possible arrangement is equally likely, making it a reliable way to generate random permutations.