About this tool
Random strings are everywhere in software: invite and coupon codes, test fixtures, temporary file names, nonces, salts, session and reset tokens. This random string generator creates them in batches from any alphabet you like, using your browser’s cryptographically secure random number generator, so the results are safe to use as tokens, not just as placeholder text.
How to use it
- Set the length (1–256) and how many strings you need (up to 50).
- Pick character sets, or type a custom alphabet to match an exact format. Duplicate characters are removed automatically, and any characters work, including non-Latin letters and emoji.
- Turn on No look-alikes for codes people will read or type, then copy the list or download it as a text file. Press G for a new batch.
The line under the button shows the alphabet size and how many bits of entropy each string has.
Common alphabets
Click Use to fill in the alphabet and a sensible length.
| Alphabet | Good for | |
|---|---|---|
Hexadecimal0123456789abcdef |
Tokens, IDs, salts. 32 hex characters = 128 bits. | |
Alphanumeric (base62)ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 |
Compact tokens with no symbols. 22 characters ≈ 131 bits. | |
Crockford Base320123456789ABCDEFGHJKMNPQRSTVWXYZ |
Codes people read aloud or type: no I, L, O or U. 10 characters = 50 bits. | |
Uppercase + digitsABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 |
Coupon and invite codes, booking references. | |
Digits only0123456789 |
Numeric PINs and one-time codes (6 digits ≈ 20 bits: only safe with rate limiting). | |
URL-safe (base64url)ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ |
Tokens in URLs and file names. 22 characters = 132 bits. |
How long should a random string be?
Each character adds log2(alphabet size) bits: 4 for hex, about 5.95 for alphanumeric, 5 for Base32. Use what the string protects to decide:
- Secret tokens (password reset links, session IDs, API keys): at least 128 bits, e.g. 32 hex or 22 alphanumeric characters. Nobody can guess these.
- Unique IDs that must not collide: with n strings of b bits, the chance of any duplicate is about
n² / 2b+1. A billion 80-bit IDs have roughly a 1 in 2.4 million chance of a single collision. - Human-typed codes (coupons, invites): 8–10 Base32 characters (40–50 bits) are plenty when the server limits attempts.
Generate random strings in code
Use a cryptographically secure source such as crypto.getRandomValues, Node’s crypto or Python’s secrets. Math.random() and Python’s random module are predictable and must never be used for tokens.
function randomString(length, alphabet) {
const limit = 256 - (256 % alphabet.length); // avoid modulo bias
let out = '';
while (out.length < length) {
for (const byte of crypto.getRandomValues(new Uint8Array(length))) {
if (byte < limit && out.length < length) out += alphabet[byte % alphabet.length];
}
}
return out;
}
randomString(32, '0123456789abcdef');const crypto = require('node:crypto');
crypto.randomBytes(16).toString('hex'); // 32 hex characters
crypto.randomBytes(32).toString('base64url'); // 43 URL-safe characters
const abc = 'ABCDEFGHJKMNPQRSTVWXYZ0123456789';
Array.from({ length: 10 }, () => abc[crypto.randomInt(abc.length)]).join('');import secrets, string
secrets.token_hex(16) # 32 hex characters
secrets.token_urlsafe(32) # 43 URL-safe characters
alphabet = string.ascii_letters + string.digits
"".join(secrets.choice(alphabet) for _ in range(32))openssl rand -hex 16 # 32 hex characters
tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 32; echo # 32 alphanumeric (Linux / macOS)The limit check in the JavaScript example avoids modulo bias: with a 62-character alphabet, byte % 62 would pick the first 8 characters slightly more often. This tool uses the same rejection-sampling approach.
Need something more specific? Use the password generator for passwords, the API key generator for prefixed keys, or the UUID generator for standard IDs.
FAQ
How do I generate a random string?
Choose a length and character set above and the strings appear instantly. In code, use crypto.getRandomValues() in browsers, crypto.randomBytes() in Node.js, or the secrets module in Python.
How do I generate a random alphanumeric string?
Keep lowercase, uppercase and digits selected (the default) and turn off symbols. Each character then comes from 62 possibilities, about 5.95 bits each.
Is Math.random() used?
No. Math.random() is not cryptographically secure. This tool only uses crypto.getRandomValues().
How unique are the strings?
Uniqueness depends on the entropy. A 32-character string from a 62-character alphabet carries about 190 bits, so a collision is practically impossible.
Can I generate strings with emoji or non-Latin characters?
Yes. Put any characters into the custom alphabet; they are treated as whole characters, not bytes.