Random Promo Code Generator
Generate unique, secure random promo codes with custom length, prefix, character sets, and batch export. Cryptographically random, no duplicates.
About
Promotional codes require cryptographic unpredictability. A guessable pattern (sequential numbers, dictionary words, short alphanumerics) exposes your system to brute-force enumeration. An attacker cycling through 364 = 1,679,616 possible 4-character alphanumeric codes can drain a campaign budget in minutes. This generator uses the browser's crypto.getRandomValues() CSPRNG, producing codes with entropy of log2(PL) bits, where P is pool size and L is code length. A 10-character code from a 62-character pool yields ~59.5 bits of entropy, making enumeration computationally infeasible.
The tool enforces uniqueness via hash-set deduplication across the full batch. Codes support configurable prefixes (brand identity), separators (readability), and mixed character sets. Note: the maximum unique code count is bounded by PL. Requesting more codes than the pool allows will halt generation and report the shortfall. Pro tip: avoid visually ambiguous characters (0/O, 1/l/I) in printed campaigns by enabling the "Exclude Ambiguous" option.
Formulas
The entropy of a randomly generated code determines its resistance to guessing attacks. Entropy is calculated as:
where H = entropy in bits, L = code length (excluding prefix, suffix, separators), P = character pool size (number of distinct characters).
The total number of unique codes possible in the configuration space:
The probability of guessing a valid code in a single attempt:
where n = number of active (issued) codes. For a batch of 10,000 codes with L = 10 and P = 62, this yields p ≈ 1.19 ร 10โ14.
Collision probability (Birthday bound) when generating n codes without deduplication:
This tool bypasses the birthday problem entirely by enforcing uniqueness through Set-based deduplication. Each generated code is checked against all previously generated codes in O(1) average time. If the requested batch size n approaches Nmax, generation halts to prevent infinite loops.
Reference Data
| Code Length | Pool Size | Unique Combinations | Entropy (bits) | Brute-Force Time @ 1M/s | Use Case |
|---|---|---|---|---|---|
| 4 | 36 (A-Z+0-9) | 1.68M | 20.7 | 1.7 sec | One-time flash sales (low risk) |
| 6 | 36 | 2.18B | 31.0 | 36 min | Email campaigns |
| 8 | 36 | 2.82T | 41.4 | 32.7 days | General purpose coupons |
| 8 | 62 (A-Z+a-z+0-9) | 218T | 47.6 | 6.9 years | High-value discounts |
| 10 | 62 | 839Q | 59.5 | 26.6K years | Gift cards, subscriptions |
| 12 | 62 | 3.23 ร 1021 | 71.5 | 102M years | License keys |
| 16 | 62 | 4.77 ร 1028 | 95.3 | >1015 years | Cryptographic tokens |
| 6 | 10 (0-9 only) | 1M | 19.9 | 1 sec | SMS verification PINs |
| 8 | 32 (no ambiguous) | 1.10T | 40.0 | 12.7 days | Printed vouchers (legibility) |
| 4 | 26 (A-Z only) | 456,976 | 18.8 | 0.46 sec | Simple referral codes |
| 10 | 36 | 3.66 ร 1015 | 51.7 | 116 years | E-commerce standard |
| 20 | 62 | 7.04 ร 1035 | 119.1 | >1022 years | Enterprise API keys |