Randomness, shuffles and seeds
Pseudo-random numbers
Software usually cannot flip a physical coin. Instead it uses a pseudo-random number generator (PRNG): a deterministic recipe that turns a starting number, the seed, into a long sequence of numbers which pass statistical tests for randomness. Start from the same seed and you get exactly the same sequence.
That sounds like a weakness but it is a scientific strength. A result that anyone can reproduce can be checked, debugged and taught. This site shows the seed it used so that you can repeat any experiment.
A fair shuffle
The Fisher–Yates shuffle goes through the deck from the last position to the first, swapping each card with a randomly chosen card at or before it. Each of the 52! orderings is then exactly equally likely, provided the random choices are uniform.
A common wrong approach is to swap every card with any random position in the deck. It looks harmless, but with 52 cards it produces 52^52 equally likely swap sequences which cannot divide evenly into 52! orderings, so some orderings are more probable than others.
for i from n − 1 down to 1: j = random integer from 0 to i swap(deck[i], deck[j])Seeds are not for security
The generator used here is designed for simulation and teaching. It is not suitable for passwords, encryption or anything where unpredictability matters against an adversary. Those uses need a cryptographically secure generator.
Random does not mean evenly spread
Genuinely random sequences contain streaks and clusters. Flip a fair coin 100 times and a run of six or more identical results is likely. If a sequence looks too evenly mixed, that is a reason for suspicion, not reassurance. Past results do not change the probabilities of independent future ones.
Check your understanding
Why does the same seed give the same results?
The generator is deterministic: its entire output is fixed by its starting state.
How many distinct orderings of a 52-card deck exist?
52! ≈ 8.07 × 10^67.
Why should a fresh seed be chosen by an event such as a button press?
Because a freshly random seed must come from outside the deterministic recipe, for instance the browser's entropy source.