Random card generator
Cards dealt from a shuffled standard deck, one at a time or as a hand, with no card repeated.
How the deck is shuffled
The deck starts in order, 2 to ace in each of spades, hearts, diamonds and clubs, then is shuffled with the Fisher–Yates algorithm: for each position from the last to the second, it swaps the card there with a card picked at random from that position or any position before it. That takes 51 swaps for a full deck, and because the random pick at each step is uniform, every possible order of the deck comes out with exactly the same chance. The cards are then dealt from the top.
Each pick uses rejection sampling on the browser’s cryptographic generator, so a choice among 52 positions is exactly 1 in 52 and never slightly tilted by modulo bias. The order matters too: a common mistake, swapping each card with any position in the whole deck, produces 5252 equally likely sequences of swaps, which can’t be shared evenly among the 52! orders, so some orders come up more often than others. The guide to fair shuffling and modulo bias shows the difference with a small deck.
Hand shuffling needs more work than it seems. Dave Bayer and Persi Diaconis calculated in 1992 that a 52-card deck needs about seven riffle shuffles to be well mixed; fewer leave noticeable traces of the earlier order.
How many orders a deck can be in
The first card can be any of 52, the second any of the 51 left, and so on, so a deck has 52 × 51 × … × 1 = 52! possible orders:
52!80,
That number has 68 digits. With two jokers there are 54! orders, about 2.31 × 1071. Hands ignore the order of the cards within them, so the number of different hands of k cards is the binomial coefficient C(52, k): 1,326 two-card hands, 2,598,960 five-card hands, 133,784,560 seven-card hands and 635,013,559,600 thirteen-card hands.
The chance of particular draws
| Draw | Chance | Percentage |
|---|---|---|
| A specific card, such as the ace of spades, in one card | 1 in 52 | 1.92% |
| An ace in one card | 1 in 13 | 7.69% |
| A jack, queen or king in one card | 3 in 13 | 23.08% |
| A pair in two cards | 1 in 17 | 5.88% |
| Two aces in two cards | 1 in 221 | 0.45% |
| Two cards of the same suit | 4 in 17 | 23.53% |
| An ace and a ten, jack, queen or king in two cards | 32 in 663 | 4.83% |
| At least one ace in five cards | 18,472 in 54,145 | 34.12% |
| At least one ace in thirteen cards | 14,498 in 20,825 | 69.62% |
For a pair in two cards, the first card can be anything; the second must be one of the 3 cards of the same rank among the 51 left, so the chance is 3 in 51, or 1 in 17. For an ace in five cards it is easier to count the hands with no ace, C(48, 5) of the C(52, 5), and subtract that share from 1.
Five-card poker hands
Draw five cards and the tool names the poker hand. Every one of the 2,598,960 five-card hands is equally likely, so the chance of each category is the number of hands in it divided by 2,598,960. Each hand counts once, in its highest category: a straight flush is not also counted as a flush or a straight, and the royal flush (ten to ace of one suit) is shown apart from the other straight flushes. An ace can be high (10-J-Q-K-A) or low (A-2-3-4-5) in a straight.
| Hand | Hands | Chance | About 1 in |
|---|---|---|---|
| Royal flush | 4 | 0.00015% | 649,740 |
| Straight flush (not royal) | 36 | 0.0014% | 72,193 |
| Four of a kind | 624 | 0.024% | 4,165 |
| Full house | 3,744 | 0.144% | 694 |
| Flush (not straight) | 5,108 | 0.197% | 509 |
| Straight (not flush) | 10,200 | 0.392% | 255 |
| Three of a kind | 54,912 | 2.11% | 47.3 |
| Two pair | 123,552 | 4.75% | 21.0 |
| One pair | 1,098,240 | 42.26% | 2.37 |
| High card (none of the above) | 1,302,540 | 50.12% | 2.00 |
| All five-card hands | 2,598,960 | 100% | – |
The counts follow from choosing ranks and suits. Four of a kind, for example, is 13 choices of the rank times 48 choices of the fifth card, 624 hands. A full house is 13 × C(4, 3) for the three of a kind times 12 × C(4, 2) for the pair, 3,744. These figures are for five cards dealt from a full deck; games where you choose your best five from seven cards have different odds.
Questions
Is each card equally likely?
Yes. The deck is shuffled with the Fisher–Yates method using your browser’s cryptographic generator, which makes every one of the 52! orders of the deck equally likely, so every card has the same 1 in 52 chance of coming first and every hand of a given size is equally likely.
Can the same card come up twice?
Not within one draw, because cards are dealt without replacement, as from a real deck. Each new draw shuffles a full deck unless you tick “Keep drawing from the same deck”, in which case the cards already dealt stay out until you shuffle a new deck.
What do the jokers do?
Ticking “Add two jokers” makes a 54-card deck. The jokers are dealt like any other card and have no suit or rank, so five-card draws that include a joker are not given a poker hand name.
Has anyone ever shuffled a deck into the same order before?
Almost certainly not, if the shuffles were thorough. There are about 8.07 × 10^67 orders of a 52-card deck, so even a billion shuffles a second since the universe began would have covered a vanishingly small fraction of them. Casual hand shuffles are less thorough and often leave runs of the original order.
Why is a hand of two pair more common than three of a kind?
Because there are more ways to make it. Two pair can be built from 123,552 of the 2,598,960 five-card hands, three of a kind from only 54,912. Poker ranks hands by how rare they are, so three of a kind beats two pair.