Random string generator
Generate random strings from hex, base64url, alphanumeric or custom character sets, in bulk, with prefixes, suffixes and an exact entropy readout.
- Runs in your browser
- Nothing you enter is sent
- Free, no account
Generated on your device, sent nowhere. Every character comes from crypto.getRandomValues with rejection sampling, so each symbol in your alphabet is equally likely — no modulo bias, and no Math.random anywhere in this page.
The safe default: survives URLs, filenames, shell arguments and spreadsheets untouched.
Effective alphabet — 62 characters
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789Added before, not random.
Added after, not random.
Drops i I l L 1 | o O 0 so the string can be read off a screen or dictated without mistakes. It shrinks the alphabet, so the entropy figure updates too.
Discards a string if it repeats one already generated. Only matters for short strings over a small alphabet.
Only 0 unique strings were possible with this alphabet and length. Make the strings longer, widen the alphabet, or turn off “No duplicates in the batch”.
How to generate random strings
- Choose a character set. Alphanumeric is the safe default — it survives URLs, filenames, shell arguments and spreadsheets untouched. Pick hex if the value has to sit alongside hashes, base64url if it goes in a URL, digits if it will be read aloud.
- Set the length. The panel shows the bits per character for the alphabet you chose, so you can work backwards from a target: 128 bits of base64url is 22 characters, 128 bits of hex is 32.
- Add a prefix or suffix if you want the values to be self-describing. Both are fixed text and add no entropy, which the tool states plainly.
- Generate in bulk. Up to 500 at a time, copyable as a block or downloadable as a plain text file, one per line.
Bits per character, by alphabet
Entropy is length multiplied by the base-2 logarithm of the alphabet size. This table saves you the arithmetic — the last two columns give the length needed to reach the two thresholds that matter in practice.
| Character set | Size | Bits per character | Length for 128 bits | Length for 256 bits |
|---|---|---|---|---|
| Digits (0–9) | 10 | 3.32 | 39 | 78 |
| Hexadecimal | 16 | 4.00 | 32 | 64 |
| Lowercase alphanumeric | 36 | 5.17 | 25 | 50 |
| Mixed-case alphanumeric | 62 | 5.95 | 22 | 44 |
| Base64URL | 64 | 6.00 | 22 | 43 |
| Printable ASCII | 94 | 6.55 | 20 | 40 |
What these strings are good for
- API keys and access tokens. 32 base64url characters is 192 bits, comfortably
past any brute-force concern. Prefix them (
sk_live_,pk_test_) so they are recognisable in logs and so a leaked key can be identified by scanning tools. - Session identifiers and CSRF tokens. The OWASP guidance is at least 128 bits from a cryptographically secure source, which is what this page produces.
- Database seed data and test fixtures. Bulk mode with a prefix gives you a few hundred unique, obviously-fake values in one click.
- Coupon, invite and licence codes. Use the uppercase alphanumeric set with ambiguous characters excluded so the code can be read over the phone without a spelling alphabet.
- Salts and nonces you are handling by hand. Hex is usually the format the surrounding tooling expects.
- Temporary filenames and cache-busting suffixes. Lowercase alphanumeric avoids every case-sensitivity trap across operating systems.
Why the randomness source matters
A surprising number of "random string" pages are built on Math.random. That
function is designed to be fast, not unpredictable: its internal state can be reconstructed
from a modest number of consecutive outputs, after which every future value is known. For a
dice-rolling animation that is fine. For an API key it is a vulnerability.
This page uses crypto.getRandomValues, which is backed by the operating system's
entropy pool — the same source a server-side library would use. It also avoids a subtler
problem: converting a 32-bit random number into an index with a plain % makes the
first few characters of the alphabet slightly more likely than the rest, because 232
is not divisible by 62. Draws landing in the final partial bucket are discarded and retaken, so
every character is exactly equally likely.
Custom alphabets and duplicate characters
If you supply your own character set, duplicates are collapsed before generation. A character listed twice would otherwise appear twice as often, quietly reducing the real entropy while the figure on the page claimed otherwise. Collapsing them keeps the alphabet size — and the bits-per-character number — truthful.
Choosing a length
For anything that acts as a credential, 128 bits is the standard floor and 256 bits is the belt-and-braces answer. For values that only need to be unique rather than unguessable — a cache key, a filename — 64 bits is already enough that a collision is not going to happen in your lifetime. Where the value will be typed by a human, trade length against the alphabet: uppercase alphanumeric with ambiguous glyphs removed at 12 characters is still 60 bits, and far less error-prone to transcribe than a shorter dense string.
Questions
Can I use these as API keys or session tokens?
Yes, provided they are long enough. A 32-character base64url string is 192 bits, which is far beyond anything guessable; 22 characters is 132 bits and still ample. The randomness comes from crypto.getRandomValues, the same source a server-side library would use, and rejection sampling keeps every character equally likely.
Why does the tool remove duplicate characters from a custom set?
Because a character listed twice would otherwise be twice as likely to appear, which quietly reduces the entropy while the maths on the page claimed otherwise. Collapsing duplicates keeps the alphabet size — and therefore the bits-per-character figure — truthful.
What does "exclude ambiguous characters" remove?
i, I, l, L, 1, |, o, O and 0 — the glyphs that people confuse when reading a code off a screen or dictating it over the phone. It shrinks the alphabet, so the entropy figure drops accordingly; compensate by adding a couple of characters to the length.
Do the prefix and suffix count towards the strength?
No, and the tool says so. A prefix such as sk_live_ is public structure, not secret material, so only the random middle section contributes entropy. It is still useful for making keys self-describing in logs and dashboards.