Making a cup draw with the National Lottery
A detour into the bizarre cryptographic world of a chess competition secretary.
How would you conduct a provably fair random draw?
It's easy enough with balls or pieces of paper in a bag, although even this doesn't make you immune to allegations of "cooled balls" and other such fiddling1. You also need witnesses, and however many people are in the room, someone can always claim that they're all in on the scam.
Video doesn't help. I can run the draw several times and release only the recording that gives the result I want. Using a random number generator or computerised shuffle makes this even quicker and easier. I can prove that there was a draw that gave that outcome, but not that it was the only draw.
So how do you run a draw that is fair, that can be done remotely, and that anyone can check after the fact? Well, I recently hit this problem in the (admittedly) incredibly low-stakes environment of the Sheffield & District Chess Association. Historically, we made draws by shuffling bits of paper in a bag, which works fine, but takes time and needs people to get in a room together. This is the sort of problem I enjoy far too much, so I sat down to think about it.
Verifiability
If I want anyone to be able to check the draw process afterwards, then it needs to be deterministic: the same inputs must always give the same outcome. Only then can anybody else 'replay' the draw and check that they get the same result. This is what allows the draw to be carried out remotely without witnesses.
Of course, if I control all these inputs, then I can still fix the draw - so we also need an unpredictable random input that is public and that I can't reasonably control. Cryptographers would call this a randomness beacon.
It so happens that in the UK we have a very well-known randomness beacon that has been running every week since 1994: the National Lottery. It's published at set times, everyone trusts it, and if I could predict or control it, I'd be on a yacht somewhere rather than messing around doing this kind of thing.
When I announce a draw, I say what the draw will be named (e.g. "Cup Quarter-Final 2026"), the teams that are in it (and their ball numbers), and I pick a future Lotto draw that will be the source of the random input. At that point, my involvement with the draw is basically done: I have no further discretion over the process. Everyone has all the information they need to reproduce the draw themselves. The Lotto balls will drop as they will, and that determines the outcome.
I was rather pleased with this, until I found out that the Internet Engineering Task Force have used a very similar method since 2000 to choose the members of their Nominations Committee.2
Fairness
The Lotto result (ignoring the bonus ball) is 6 balls from 1-59, so there are 45,057,474 combinations. But how do you get from 6 numbers to a random shuffle?
This is where cryptographic hash functions come in. These functions turn some text x into a really big number f(x). The trick is to give each ball its own text, hash it, and sort the balls by their hashes. That gives a shuffled order. Hash functions have a few useful properties that make this work:
- the same x always gives the same f(x) (it's a mathematical function);
- f(x) looks completely random, with no apparent relationship to x (it behaves like a random oracle);
- if x changes, even only slightly (say, if one Lotto number were to change), f(x) changes dramatically and unpredictably (the avalanche effect)
In our case, all the draw inputs go into one line of text called the seed: the draw name3, the Lotto numbers (in ascending order), the number of teams, and the number of byes, with a vertical bar between each. For instance:
cup quarter-final 2026 | 4 8 15 16 23 42 | 8 | 0
Each team's ball, numbered i, gets its own text (its own xi) that is seed + # + i, for example:
cup quarter-final 2026 | 4 8 15 16 23 42 | 8 | 0#1
Then, we hash each ball's text, and they line up in order of f(xi), smallest first. That line is the order that the balls are 'drawn' in. Any byes needed are given to the first balls drawn, and the rest pair off in the order drawn: first against second, third against fourth, and so on. That is the whole method.4
| Ball | Text | Hash | Drawn |
|---|
Given that I don't know what the xs will be until the Lotto is drawn, there's no way for me to set the non-random inputs of the draw (like the draw name, or choosing who gets which ball) in a way that meaningfully favours any team.5
The hash function used is called SHA-256 and is widely used to ensure online security. There is no known practical way to predict or manipulate its output to give a chosen result, and no evidence of any systematic bias; if such a weakness were ever found, you could wreak a lot more havoc than just fixing a cup draw.
Because the hash values behave like random numbers, every ball should get roughly the same chance of any particular outcome.6
Trust
The really nice thing about this arrangement is that you don't have to take my word for anything. The only things you need to trust are the Lotto and SHA-256.
I made a web page that lets anyone run the process, but you don't even need to trust that - this post has enough information for anyone who can code, or your favourite AI, to write their own version and check a draw independently.
For completeness, when I announce a draw by email I also give the SHA-256 hash of the page's code. This works like a fingerprint: any change to the code, however small, gives a different hash, so anyone can check that I haven't changed the draw algorithm after the Lotto numbers were known.
It's a lot of cryptography for very low stakes. But that's what makes it fun: you can watch the Lotto draw live and know the fixtures before I've emailed them out.
-
In 2016 Sepp Blatter, by then banned from football, told the Argentine paper La Nación that he had seen European draws fixed with balls chilled beforehand, so whoever made the draw could find them by touch. UEFA called the claim "completely absurd". Nobody can prove it either way, which is the problem.↩
-
First as RFC 2777 in 2000. The IETF method combines three or four public sources for more entropy.↩
-
The draw name lets the Cup and the Plate (two competitions we run concurrently) use the same Lotto draw and still come out differently.↩
-
The fine print, for anyone writing their own version. The draw name can only use plain (ASCII) letters, digits, spaces and punctuation. It is put into lower case, spaces are removed from each end, and any run of spaces becomes a single space, so nobody gets a different draw by copying the announcement slightly wrong. The Lotto numbers are written in ascending order with a single space between them. The four parts of the seed are joined by a space, a vertical bar and a space. Numbers are written the ordinary way, with no leading zeros, and nothing goes between the seed, the
#and the ball number. The hash is the SHA-256 of that text, written as 64 lowercase hexadecimal characters. They are all the same length, so sorting them alphabetically, with0to9beforeatof, puts the smallest first. If two balls ever had the same hash, which will not happen in practice, the lower ball would go first. The draw page gives the same rules more formally under "The method in detail".↩ -
So as not to give the impression of deliberately giving any team a particular ball, I assign ball numbers alphabetically. There is a theoretical loophole, though: I choose the draw name. A name like "aQa78dfa03amWwa" would probably raise eyebrows, but I could try each of the few dozen reasonable names ("Cup QF", "Cup Quarter-Final", "Richardson Cup Quarter-Final"...), simulate every possible Lotto result, and pick whichever suited my team best. That would raise my chance of drawing the weakest team from 14.29% to about 14.30%, one extra good draw in about 8,500: at a few draws a season, my cheating would pay off less than once a millennium. If this were a realistic concern, we could add more randomness to the mix - using both rounds of the Lotto draw, for instance.↩
-
Like 45,057,474 draws from a bag, the results aren't spread perfectly evenly, so for any draw name some outcome comes up very slightly more often than it should. In the table above, the 'luckiest' ball gets choice of venue 50.008% of the time and the unluckiest 49.989%: one extra choice of venue in about 5,000 draws. That's about a hundredth of the bias in a tossed coin, which lands the way it started 50.8% of the time. Which ball is luckiest depends on the draw name, so the tiny bias changes with every draw and evens out over the long term.↩