Random String Generator
Make secure random strings, tokens and codes, up to 100,000 at once. Or paste yours to see the strength of each one. Nothing leaves your browser.
- 0
- Strings
- 0
- Lowest bits
- 0
- Issues
Your new string
Press Generate (Alt G) for 10 at once, or paste strings in the editor to check them.
On this page
About Random String Generator
Updated
Random String Generator makes strings for passwords, tokens, secrets and codes. Each character comes from your browser's secure random source, and each character of the set is exactly as likely as the next. Make one, or 100,000 at once. With Unique on, every string in the list is different. Use it as a random code generator for coupon, promo and invite codes.
It also checks strings. Paste tokens, keys or a .env file, and each string gets its length, its characters, its bits and its strength. In a .env file, only names with words such as KEY, SECRET or TOKEN are checked. A hidden space, a look-alike letter or a duplicate is marked. Want a prefix and a checksum on every key? Use the API Key Generator: both are on when it opens. For a JWT secret, a Django or a Laravel key, use the Secret Key Generator.
How to use it
- Set Count (1 to 100,000), Format and Length next to Generate. On a phone they are under More.
- Set the rest in Options: which characters, Look-alikes, a Prefix, and Unique.
- Press Generate (Alt G). The new strings replace the editor text; Undo brings the old text back.
- To check strings, paste them one per line, or load a file. Results shows each one with its strength, and Notes lists what is wrong. Remove duplicates (Alt D) keeps the first of each.
- Open Code to make the same kind of string in your own program.
Which format to pick
- Letters and digits for passwords and tokens that people copy. Add symbols only when the system that takes them allows every symbol.
- Hex and Base64 for keys that code reads. You set the bytes; hex writes each byte as 2 characters, Base64 writes 3 bytes as 4. Base64 URL-safe has no
+,/or=, so it can go in a URL or a cookie as it is. - Pattern (codes) for coupon, promo, voucher and invite codes that people type.
- The Secrets group for a framework that expects one shape:
openssl rand -hex 32,openssl rand -base64 32, a JWT HS256 secret, a DjangoSECRET_KEY, a LaravelAPP_KEY, or an Auth.jsAUTH_SECRET.
For a unique ID, use the UUID Generator.
How many bits you get
The same length gives very different strength with different characters. Bits per character, and the length for 128 bits:
Characters Bits each Length for 128 bits
0-9 3.3 39
hex (0-9 a-f) 4.0 32
A-Z without I and O, plus 2-9 (32 characters) 5.0 26
A-Z a-z 0-9 5.95 22
Base64 6.0 22
A-Z a-z 0-9 + symbols 6.2 21Common errors
A space at the end
A key copied from a terminal, a PDF or a spreadsheet often brings a space with it. It does not show, but the key no longer matches.
API_TOKEN=api_cJskcKpWo55mI2kQCAbDFda7jYTSCs8u1frW3r␣Tool:A space at the end. A string with a space in it fails in a header or a .env file. Delete it.
API_TOKEN=api_cJskcKpWo55mI2kQCAbDFda7jYTSCs8u1frW3rAn invisible character
Chat apps and web pages put zero-width spaces into long strings so they wrap. The tool names the character and marks its place.
Td5Iydxid3HkQnIxXePvgWMNGG2XcZI5Of-eLahpca0Tool:An invisible zero-width space (U+200B) at character 13. Chat apps and web pages can add it.
Td5Iydxid3HkQnIxXePvgWMNGG2XcZI5Of-eLahpca0A letter from another alphabet
The Cyrillic а and the Latin a look the same. A key with the wrong one never matches, and no one can see why.
pаss-D9JFOLMJF2e0bjxUh3vqkHZ6Tool:"а" at character 2 is U+0430, not the Latin "a" it looks like. The string will not match.
pass-D9JFOLMJF2e0bjxUh3vqkHZ6Make a random string in code
Three one-liners for a 32-byte token. The Code view has nine languages and follows your settings.
openssl rand -hex 32require("node:crypto").randomBytes(32).toString("base64url");import secrets
secrets.token_urlsafe(32)Random string resources
- MDN: Crypto.getRandomValues()The browser's secure random source, which this tool uses. Why Math.random is not for secrets.
- Python: secrets moduletoken_hex, token_urlsafe and choice, and how many bytes a token needs.
- Node.js: crypto.randomBytesRandom bytes in Node.js, with randomInt for picking from a set without bias.
- OWASP Secrets Management Cheat SheetHow to make, store, rotate and revoke keys and secrets.
- GitHub: Behind the new token formatsWhy GitHub tokens have a prefix and a 6-character CRC-32 checksum, the scheme this tool's checksum follows.
- Password strength and entropy on WikipediaHow bits of entropy are worked out from the length and the set of characters.
Random string FAQ
Can you generate a random string?
Yes. The Result shows a fresh 32-character string when the page opens, with a Copy button. Press Generate for up to 100,000 at once. Set the length and the format next to Generate, and the characters in Options.
At most 10 million characters at once, for example 100,000 strings of 100.
The strings come from your browser's secure random source, crypto., so they are fit for passwords, tokens and keys.
How can I generate a random 20-character string?
Set Length to 20 next to Generate (under More on a phone) and press Generate. With letters and digits (62 characters), 20 characters give 119 bits, which no one can guess. With digits only, 20 characters give 66 bits.
How can I generate a random 16-character string, or a string of numbers?
Set Length to 16 and press Generate. With letters and digits, 16 characters give 95 bits: fine for a session ID or an invite link, short of the 128 bits a secret key needs.
For numbers only, pick Digits only in Format. Each digit gives 3.3 bits, so 16 digits give 53 bits and a PIN of 6 digits gives about 20. For a number to guess or type, that is fine. For a secret, use 39 digits or more.
How can I generate a random 32-character string?
32 characters of letters and digits is the start setting: press Generate. That is 190 bits.
For 32 hex characters, pick Hex and set Bytes to 16: each byte is two hex digits. In a shell, openssl rand -hex 16 gives the same. Note that openssl rand -hex 32 gives 64 characters, not 32.
How do I generate a random string in code?
Use your language's secure random source: crypto. or crypto. in Node.js, the secrets module in Python, random_bytes and random_int in PHP, RandomNumberGenerator in C#, SecureRandom in Java and Ruby. Open the Code view: it shows the code for your settings in nine languages.
Do not use Math., Python's random or PHP's rand() for secrets. Their output can be predicted from earlier values.
How long should a random string be?
It depends on what it guards. A secret key, an API key or a session token needs 128 bits or more: 22 letters and digits, 32 hex digits or 16 bytes. 256 bits (32 bytes) is common for signing keys. A coupon code that a server rate-limits can be short, for example 8 characters (40 bits).
The tool shows the bits and the strength of each string, so you can compare settings.
What are bits of entropy?
The number of yes-or-no guesses it takes to cover every possible string. A string of n characters from a set of k characters has n × log2(k) bits. Each extra bit doubles the work of a guesser. 128 bits is out of reach for any computer.
The figure is true only for strings made at random. A word, a name or a date has far fewer bits than its length suggests.
How do I make coupon codes that people can type?
Pick Pattern (codes) and type a pattern such as XXXX-XXXX-XXXX, the start setting. X is a capital or a digit without 0, O, 1 and I, so nobody mixes them up. # is a digit, ? is a capital letter, and any other character stays as it is: SALE-XXXX keeps SALE. Leave Unique on and every code in the list is different.
Are my strings sent anywhere?
No. The tool makes and checks the strings in your browser. Nothing is uploaded and nothing is logged. You can check this in your browser's network tab while you press Generate.