Skip to content
Aarrange

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
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result

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

  1. Set Count (1 to 100,000), Format and Length next to Generate. On a phone they are under More.
  2. Set the rest in Options: which characters, Look-alikes, a Prefix, and Unique.
  3. Press Generate (Alt G). The new strings replace the editor text; Undo brings the old text back.
  4. 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.
  5. 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 Django SECRET_KEY, a Laravel APP_KEY, or an Auth.js AUTH_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:

Bits per character
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         21

Common 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.

Invalid
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.

Fixed
API_TOKEN=api_cJskcKpWo55mI2kQCAbDFda7jYTSCs8u1frW3r

An 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.

Invalid
Td5Iydxid3Hk​QnIxXePvgWMNGG2XcZI5Of-eLahpca0

Tool:An invisible zero-width space (U+200B) at character 13. Chat apps and web pages can add it.

Fixed
Td5Iydxid3HkQnIxXePvgWMNGG2XcZI5Of-eLahpca0

A 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.

Invalid
pаss-D9JFOLMJF2e0bjxUh3vqkHZ6

Tool:"а" at character 2 is U+0430, not the Latin "a" it looks like. The string will not match.

Fixed
pass-D9JFOLMJF2e0bjxUh3vqkHZ6

Make a random string in code

Three one-liners for a 32-byte token. The Code view has nine languages and follows your settings.

Shell
openssl rand -hex 32
JavaScript
require("node:crypto").randomBytes(32).toString("base64url");
Python
import secrets

secrets.token_urlsafe(32)

Random string resources

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.getRandomValues, 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.randomBytes or crypto.randomInt 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.random(), 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.