Full character control
Toggle uppercase, lowercase, numbers, and symbols independently, or supply your own custom character set.
Any length
Generate strings from 1 to 128 characters long.
Bulk generation
Generate up to 50 strings at once and copy them all together, one per line.
How long should a random code be?
If you create many codes (coupons, invite codes, order references), they need to be long enough that two don’t come out the same by chance. For codes using A–Z and 0–9 (36 characters):
| Length | Possible codes | Chance of any duplicate in 10,000 codes | In 1,000,000 codes |
|---|---|---|---|
| 6 | 2.2 billion | 2.3% | Almost certain |
| 8 | 2.8 trillion | 0.002% | 16% |
| 10 | 3.7 quadrillion | Practically zero | 0.014% |
| 12 | 4.7 quintillion | Practically zero | Practically zero |
Rule of thumb: 8 characters is plenty for a few thousand codes; use 10–12 for hundreds of thousands or more. Even then, check new codes against the ones you’ve already issued.
Tips for readable codes
- Codes people type by hand: use a custom set without look-alike characters, for example
ABCDEFGHJKMNPQRSTUVWXYZ23456789(no I, L, O, 0 or 1). - Codes that go in URLs or file names: stick to letters and numbers; symbols like
&,?and/can break links. - Case-sensitive or not: if people will read codes aloud or type them on a phone, use one case only (all capitals) and make the length a little longer instead.
Generate random strings in code
Python: use the secrets module (not random, which isn’t secure for tokens):
import secrets, string
alphabet = string.ascii_uppercase + string.digits
code = ''.join(secrets.choice(alphabet) for _ in range(10)) # e.g. K7Q2X9MA4T
token = secrets.token_hex(16) # 32 hex characters
url_token = secrets.token_urlsafe(16) # about 22 URL-safe charactersJavaScript (browser):
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const bytes = crypto.getRandomValues(new Uint32Array(10));
const code = Array.from(bytes, b => chars[b % chars.length]).join('');Node.js: require('crypto').randomBytes(16).toString('hex') (32 hex characters)
Command line: openssl rand -hex 16
For unique IDs in databases, a UUID is usually the better choice. Use the UUID Generator.
Need passwords instead? Use the Strong Password Generator. Need realistic names and emails for testing? Try the Fake Data Generator.
Common Mistakes to Avoid
Using this for password generation without symbols
Solution:
For actual account passwords, use the dedicated Password Generator, which is tuned for security with a strength meter.
Setting a custom character set with too few unique characters
Solution:
A very small character set makes strings easier to guess — use a broader set for anything security-sensitive.
Frequently Asked Questions
This tool is general-purpose (tokens, test data, IDs) and supports fully custom character sets; the Password Generator is tuned specifically for account security with a strength meter.
Yes — enter a custom character set and it overrides the checkbox options.
Use the secrets module: ‘’.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(10)) gives a 10-character code, and secrets.token_hex(16) gives a 32-character hex token. Avoid the random module for anything security-related, because its output can be predicted.
With letters A–Z and digits 0–9, 8 characters is enough for a few thousand codes, and 10–12 characters for hundreds of thousands or millions. Longer codes make accidental duplicates and guessing much less likely.
They’re generated with your browser’s cryptographically secure random number generator, so they’re suitable for tokens and test keys. For account passwords, the Password Generator adds strength guidance; for production API keys, generate them on your server so they never pass through a browser.

