The Fisher-Yates shuffle was originally described by Ronald Fisher and Frank Yates in their 1938 book "Statistical Tables for Biological, Agricultural and Medical Research." The modern computer-optimized version was developed by Richard Durstenfeld in 1964 and popularized by Donald Knuth in "The Art of Computer Programming."
The algorithm iterates from the last element to the first. For each position i, it randomly selects an element from positions 0 to i and swaps them.
for i from n-1 down to 1:
j = random integer where 0 <= j <= i
swap array[i] with array[j]
def fisher_yates_shuffle(deck):
for i in range(len(deck) - 1, 0, -1):
j = random.randint(0, i)
deck[i], deck[j] = deck[j], deck[i]
return deck
Mathematician Persi Diaconis proved that 7 riffle shuffles are needed to adequately randomize a 52-card deck. This relates to mixing time in Markov chains.
Time Complexity: O(n) | Space: O(1) | Permutations: 52! = 8.07 x 1067
Ranked from lowest (1) to highest (11). Higher beats lower!
No matching cards. Highest card plays.
Two cards of the same rank.
Two different pairs.
Three cards of the same rank.
Five consecutive ranks (any suits).
Five cards of the same suit.
Three of a kind + a pair.
Four cards of the same rank.
Straight + flush combined.
A-K-Q-J-10 all same suit. Rarest hand!
Wild cards only! Five cards of same rank.
Queens are always wild in Follow the Queen!
Queens are always wild. When a Queen is dealt face-up, the next face-up card's rank also becomes wild. Wild cards can substitute for ANY card to make the best hand!
In low games, the lowest hand wins. Aces play low. Straights and flushes don't count against you!
A-2-3-4-5 - The perfect low hand!
A-2-3-4-6 - Second best low.
A-2-3-5-6 or A-2-4-5-6
Any 5 unpaired cards, 7-high.
Any 5 unpaired cards, 8-high. Required to qualify in most Hi-Lo games!
Pairs, or cards 9+ disqualify a low hand in "8-or-better" games.
Reading low hands: Compare from highest card down. A-2-3-4-6 beats A-2-3-5-6 because 4 < 5.
Eight-or-better: To qualify for low, all 5 cards must be 8 or lower with no pairs. If no one qualifies, the high hand wins the entire pot.
Scooping: The same hand can win both high and low! A-2-3-4-5 is both the best low AND a straight for high.