How we ran a prize draw anyone can re-check, in 66 lines of Python
Most online giveaways end with a post that says "congratulations to our winners" and nothing else. You either trust the company or you don't. We ran a small free prize draw at CarCheckHQ: 10 vehicle history report credi
Most online giveaways end with a post that says "congratulations to our winners" and nothing else. You either trust the company or you don't.
We ran a small free prize draw at CarCheckHQ: 10 vehicle history report credits for UK drivers. We wanted a result anyone could check without trusting us at all.
Under the UK advertising code, a prize draw has to be run fairly and the promoter has to be able to show it. We decided "show it" should mean anyone with Python 3 could rerun the draw at home and get the same winners.
The draw ran at 12:00 on Monday 23 November 2026. Here's how it works, the actual numbers, and the script.
The problem with "we picked at random"
If we pick the random number, we could pick it again until we liked the answer. If we pick it after seeing the entries, we could quietly add or drop an entry. So two things need to be fixed in public before anyone, including us, knows the result:
- The exact list of entries.
- A random number that nobody controls and nobody can know in advance.
Step 1: lock the entry list with a fingerprint
Every entry gets a random ID (a UUID). No names or emails go anywhere near the draw.
Before the draw, the script sorts the IDs and hashes them:
ids = sorted({row["entry_id"].strip() for row in csv.DictReader(open(a.entries)) if row["entry_id"].strip()})
list_hash = hashlib.sha256("\n".join(ids).encode()).hexdigest()
Sorting matters. Without it, the same entries exported in a different order would give a different hash and a different result.
On the morning of the draw, hours before the random round existed, we published the entry count, the ID list itself and its SHA-256. The script hashes the sorted IDs without the header line, so its fingerprint is a different string from running sha256sum on the file.
We published both before the round. Add, remove or change one ID and both fingerprints change completely.
- Entries in the draw: 6
- SHA-256 of g1-entries.csv:
180c0241d882f23dd5583144fa704e6930183cbd064b1b4a91892272aee24768 - The script's entry_list_sha256:
c07ad0e385d0b318fd8db1695ef62ceec2df26738fe302c39032ea22461a6bc5
Step 2: borrow randomness from drand
For the random number we used drand, a public randomness beacon run by the League of Entropy, a group of independent organisations. Its "quicknet" chain publishes a new value every 3 seconds, and each value is a threshold BLS signature that no single member can produce or predict.
Because rounds are on a fixed clock, you can work out which round will exist at a given moment long before it happens. We named the round in the giveaway terms weeks in advance:
GENESIS = 1692803367 # quicknet genesis time
PERIOD = 3 # seconds per round
def round_at(ts):
return max(1, -(-(ts - GENESIS) // PERIOD) + 1) # first round at or after ts
12:00:00 GMT on 23 November 2026 is Unix time 1795435200, which gives round 34210612. That round didn't exist until the draw time, and nobody could steer it.
The script fetches the round itself and takes the SHA-256 of the signature as the random value:
def fetch_round(r):
with urllib.request.urlopen(f"https://api.drand.sh/v2/beacons/quicknet/rounds/{r}", timeout=20) as f:
sig = json.load(f)["signature"]
return hashlib.sha256(bytes.fromhex(sig)).hexdigest()
- Random value for round 34210612:
6e845af45ca6030a5b19bfb320f01fb709d4141fa43fb151353b0f9e18281d0d
You can open the round in your browser at api.drand.sh/v2/beacons/quicknet/rounds/34210612, and drand's own tools can verify the signature against the League of Entropy public key.
Step 3: a seeded, unbiased shuffle
The seed mixes the drand value with the entry-list fingerprint, so the result depends on both:
seed = hashlib.sha256(f"{rnd}:{list_hash}".encode()).hexdigest()
Then it's a plain Fisher-Yates shuffle. The one detail worth copying is how it picks a random index. Taking a big hash modulo n is very slightly biased towards small numbers. So the script uses rejection sampling: it throws away any 256-bit value above the largest multiple of n and tries again.
def rand_below(n, seed, counter):
limit = (2**256 // n) * n
while True:
x = int(hashlib.sha256(f"{seed}:{counter[0]}".encode()).hexdigest(), 16)
counter[0] += 1
if x < limit:
return x % n
With 256-bit numbers the bias would have been tiny anyway, but "tiny" is a strange thing to have to explain to a winner who didn't win. Rejection sampling makes it exactly fair.
The first 10 IDs in the shuffled list win. With more than 10 entries, the next 10 would be reserves, used in order if a prize isn't claimed. There's no re-draw.
There were 6 entries in the draw, fewer than the 10 prizes, so under the terms every entry in the draw won a prize. Here's the order the script gave:
8468d540-2606-4d99-a329-e2308b4efbdb74e0f78f-4f40-4193-baa3-e6b5edca19fe898def2a-1de2-49ae-8051-9a979841dbae3acb4539-6508-4003-bff1-46c227ab3f3bf9598fed-90b0-41ea-a962-84f12c5c0200a1e8a990-21bd-4a2b-9628-00a1c67b27a1
Rerun it yourself
The whole script is 66 lines with no dependencies beyond the Python standard library. Download it from carcheckhq.com/giveaway/draw.py and check it's the same file we used:
sha256sum draw.py
# 124787266705120f0039a3cde2bfefcaf1b8e46a11a72ffb51302c1d7d56475a
Download the published list of entry IDs from carcheckhq.com/giveaway/g1-entries.csv, save it as entries.csv and check its sha256sum matches the value above. Then run:
python3 draw.py entries.csv --round 34210612 --winners 10 --reserves 10
You get a small JSON block: entries, entry_list_sha256, drand_round, drand_randomness, seed, winners and reserves_in_order. Every field should match what's on our giveaway results page. If you'd rather not touch the network, pass the random value in with --randomness and it runs fully offline.
What we'd do differently
- Publish the entry-ID list earlier. The fingerprint proves the list didn't change, but people can only rerun the shuffle once they have the list itself. Next time the list goes up the moment entries close.
- Pin the script hash in the terms from day one. We did this, and it's the bit that stops anyone (us included) from tweaking the code after seeing the drand value.
- Keep it boring. No database, no service, no admin panel. One CSV, one public random number, one script. The less there is, the less there is to argue about.
If you run a giveaway, a raffle for a club or school, or anything where people need to trust a random pick, feel free to borrow the approach. The pattern is simple: fix the entries, fix the future randomness source, publish both, and let anyone replay it.
CarCheckHQ is run by DESKLINK LTD (company 17076467, England and Wales). We're independent and not linked to the DVLA or DVSA.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.