UnipickerDraw Whitepaper
Algorithms · LESSON 10

Making safe random — SHA

Unipicker's safe random is made with a hash machine called SHA. The name sounds hard, but the idea is easy.

Concept

SHA = a classic hash machine

SHA (Secure Hash Algorithm) is a classic method: put in text and it makes a fixed-length hash (64 digits). We learned what a hash is in the earlier lesson "What is a hash?" (same input → same hash; one changed character changes it entirely). Here we learn to turn that hash into a random number for draws.

Why is SHA good as a CSPRNG? SHA satisfies both things safe random needs at once: unpredictable + reproducible. Fix the seed and you can make as much as needed, anyone can compute and verify it identically, and being a global standard it gives the same result everywhere.
Experiment

Turning SHA into a random number

A SHA hash is really a huge number (64 hex digits, 256 bits). Unipicker computes the full hash, then — since a computer can only handle a decimal precisely up to 53 bits — takes just the top 53 bits and divides by 253 to turn it into a random number between 0 and 1.

Text
Why only the top 53 bits? A computer can only handle a decimal number precisely up to 53 bits — dividing the full 256-bit hash as-is would introduce error. So Unipicker takes the hash's top 53 bits and divides by 253 (= 9,007,199,254,740,992) to get a precise random number between 0 and 1. Why make it 0–1? A 0–1 random number is a "universal ruler" — just multiply and you get any range (e.g. pick 1 of 5 → 0–1 × 5). Like a percentage, it is a common scale that works everywhere, handy once made.
Experiment

Making random in bulk — seed + number

To make lots of random numbers, append a number to the seed and run SHA: SHA(seed|0), SHA(seed|1)… each gives a completely different random number. One per entrant. (Numbering starts at 0.)

Where does the seed come from? Unipicker takes the first 16 hex digits of the DRAND number it received, converts them to decimal, and uses that as the seed. (e.g. a number like 3947128560)
Seed
EntrantInput to SHASHA-256 hash (shown partially)0–1 random
Speed testCheck how long it takes to generate random in bulk.
Each is independent, so they can be made in parallel — even millions are fast.
Principle

Why Unipicker uses the hash's top 53 bits

Unipicker first computes the full SHA hash (256 bits). Then it takes just the top 53 bits — the most a computer can handle as a decimal without error — and uses that as the random number. The full hash still carries all 256 bits of unpredictability; only the final calculation is kept precise.

2256 optionsAbout 1.2×1077 — more than the atoms in the universe
No error53 bits is exactly what a computer can handle precisely as a decimal
Exactly reproducibleSame input → same hash, same top 53 bits
UnpredictableSo many possibilities that nobody can guess
Note — the demo above sometimes shows only a shortened front for readability, but the actual random calculation uses the hash's top 53 bits.
Key pointSHA(seed + number) makes as much secure randomness as needed, taking the top 53 bits of the hash and dividing by 253. Same seed → everyone gets the same random number → verifiable.