Random String Generator
Generate cryptographically secure random strings of any length from letters, digits, hex, URL-safe or your own character set.
Was this tool helpful?
Thanks for the feedback!
This tool generates random strings from a character set you choose, such as letters and digits, hex or URL-safe characters. It is built for developers who need API keys, tokens, test data, coupon codes or temporary passwords, and it shows how many bits of entropy each string has so you can judge whether it is long enough.
The fields
- Length (characters): from 1 to 1024. The default is 16.
- How many strings: from 1 to 500 at once, one per line. The default is 5.
- Characters: the set to draw from. The options are letters and digits (62 characters), letters only (52), lowercase and digits (36), uppercase and digits (36), digits only (10), hex 0–9 and a–f (16), URL-safe letters, digits, - and _ (64), no look-alikes (56) and letters, digits and symbols (85).
- Or use your own characters (overrides the list), optional: type any characters, for example
ABCDEFGHJK23456789for voucher codes. Duplicates are removed, soAABBCbecomes a set of three.
The no look-alikes set leaves out 0, O, 1, l and I, which makes codes easier to read out over the phone or copy from a printed slip. The URL-safe set matches the alphabet used by Base64url, so its strings can go into links and file names without escaping.
How the strings are made
Each character is picked with crypto.getRandomValues, the browser's cryptographically secure random number generator. Math.random is not used, because its output can be predicted and is not meant for security.
The tool also avoids modulo bias. A random 32-bit number can take 4,294,967,296 values, which does not divide evenly by, say, 62. Taking the remainder directly would make a few characters very slightly more likely than others. The tool uses rejection sampling instead: it throws away the small top slice of values that would cause the imbalance and draws again, so every character in the set has exactly the same chance.
All of this happens in your browser. Nothing is sent to a server or saved, so the strings are seen only by you.
Entropy: how strong is a string?
The tool reports Entropy per string using:
entropy bits = length × log₂(character set size)
Each extra bit doubles the number of possible strings. The figures below are what the tool shows:
| Settings | Set size | Entropy |
|---|---|---|
| 6 digits | 10 | 19.9 bits |
| 8 lowercase and digits | 36 | 41.4 bits |
| 12 no look-alikes | 56 | 69.7 bits |
| 16 letters and digits | 62 | 95.3 bits |
| 21 URL-safe | 64 | 126 bits |
| 32 hex | 16 | 128 bits |
| 20 letters, digits and symbols | 85 | 128.2 bits |
A 6-digit code has about a million possibilities, which is fine for an OTP that expires in minutes and allows only a few tries, but far too weak for anything that can be guessed offline. For API keys, session tokens and password reset links, aim for at least 128 bits. A 32-character hex string or a 22-character URL-safe string gets you there.
The entropy figure is only accurate because the characters are chosen at random. A string you make up yourself, even with the same length and symbols, has far less real entropy.
Picking the right set
- Database IDs or file names: lowercase and digits, or hex, avoid case-sensitivity problems.
- Tokens in URLs or cookies: URL-safe.
- Codes people type by hand: no look-alikes, or a custom set without vowels so you do not spell real words by accident.
- Symbols give more bits per character, but some systems reject characters such as quotes, brackets or
&. Test before you rely on them.
Limits and messages
A length outside 1 to 1024, or a decimal, gives "Length must be a whole number from 1 to 1024." More than 500 strings gives "Generate between 1 and 500 strings at a time." A custom set with only one distinct character, like aaaa, gives "The custom character set needs at least two different characters."
For login passwords with rules about required character types, the password generator is a better fit. For standard identifiers in the 8-4-4-4-12 format, use the UUID generator.
Frequently asked questions
Are these random strings secure enough for API keys?
How is entropy calculated?
What does no look-alikes mean?
Is anything I generate stored or sent anywhere?
Can I use my own set of characters?
How many random strings can I generate at once?
Related guides
- Free Developer Tools That Replace a Dozen Browser Tabs Free developer tools grouped by job: format, convert, encode, generate and test. What each one does, which run on the server, and the limits to know f...
- How to Beautify CSS, HTML and XML (Online, VS Code, Prettier) Beautifying adds line breaks and indentation so minified CSS, HTML or XML is readable again. How the free formatters work, their limits, and VS Code a...
- How to Format JSON: Pretty-Print, Validate and Read Errors Paste JSON into a formatter to indent it and catch errors. The exact syntax rules, how to read an error position, and how to do it in VS Code, Python...