What this alphanumeric code generator is for
An alphanumeric code generator produces short identifiers made only of the ASCII letters A–Z and a–z and the digits 0–9: voucher and promo codes, order or booking references, invite tokens, ticket numbers and placeholder usernames. It uses the same secure generator as the Random String Generator, limited to three letters-and-digits character sets. If you need hex, URL-safe characters, symbols or your own alphabet, for example one without look-alike characters, use that page instead.
Choosing between the three character sets
| Setting | Characters | Bits per character | Good for |
|---|---|---|---|
| Mixed case + digits | A–Z, a–z, 0–9 (62) | about 5.95 | Codes only machines read, such as links and API references |
| Uppercase + digits | A–Z, 0–9 (36) | about 5.17 | Printed vouchers, receipts, codes read over the phone |
| Lowercase + digits | a–z, 0–9 (36) | about 5.17 | Usernames, subdomains and file names |
Mixed case is compact, but be careful where the code will be stored and compared. Many databases compare text case-insensitively by default (MySQL's default collations do), so aB3x and Ab3X count as the same value there, and a unique index can reject a code you believed was new. If codes will be typed or compared without regard to case, generate them with a single case from the start.
Look-alike characters: 0 and O, 1, I and l
This page does not filter ambiguous characters. Here is real output from five uppercase-and-digit codes of length 8:
QW7AORDM
17XL4KY9
1O6DNU2U
91NZC3IX
1RKGFLXEThe third code contains both a 1 and an O, which a customer copying from a receipt can easily confuse with I and 0. Lowercase does not solve the problem either, since l and 1 or o and 0 look alike in many fonts. You have three options:
- Build an alphabet without the troublesome characters using the Custom setting in the Random String Generator.
- Follow an established scheme such as Crockford's Base32, which leaves out I, L, O and U and treats I and L as 1 and O as 0 when reading input back.
- Normalise what people type before checking it: trim spaces, convert to uppercase and map O to 0 if your alphabet only contains the digit.
How long should a code be?
Each character multiplies the number of possible codes by the size of the alphabet, so strength grows quickly with length:
| Length | Uppercase + digits | Mixed case + digits |
|---|---|---|
| 6 | 31.0 bits | 35.7 bits |
| 8 | 41.4 bits | 47.6 bits |
| 10 | 51.7 bits | 59.5 bits |
| 12 | 62.0 bits | 71.5 bits |
Two questions decide the length. First, how likely are accidental duplicates? When you issue n codes from N possibilities, you can expect about n²/2N duplicate pairs. For 10,000 codes of six uppercase-and-digit characters that is roughly 0.02, small but not zero. Second, how easy is guessing? With 10,000 valid eight-character codes out of about 2.8 trillion, a single random guess succeeds with a probability of roughly 1 in 280 million, and rate limits on redemption make large-scale guessing impractical.
Formatting codes for people
- Group long codes into blocks, for example
K7QD-M2XP, when you print them. Insert the hyphen in your spreadsheet or code and strip it again before validation. - Add a readable prefix such as a campaign or year, and keep the random part long enough on its own.
- Usernames and handles: lowercase + digits suits temporary account names such as
user_x7k2m9. For memorable names made of words, try the Random Username Generator.
How the codes are generated
Every character is chosen independently in your browser from crypto.getRandomValues. Random 32-bit values that would favour some characters are discarded and drawn again, so each of the 36 or 62 characters is equally likely at every position. Codes can be 1 to 10,000 characters long, and each batch holds up to 10,000 codes. Each code appears in its own box with a copy button, Copy all joins the batch with line breaks, and Download saves it as a text file. Duplicates are not removed automatically, so run large batches through Remove Duplicate Lines before importing them.