Random string generator

Pick a length, how many and which characters, and get cryptographically secure random strings for tokens, API keys, test data or file names. They are made in your browser with its secure random number generator and never sent anywhere.

Presets
Up to 500 strings of up to 1,024 characters each.
Characters

Your own characters are added to the ticked ones; repeats and spaces are ignored. The prefix goes in front of every string unchanged and adds no randomness.

Entropy per string
191 bits
Characters to choose from
62
List
10 × 32 characters

128 bits or more is enough for session tokens, API keys and secrets: nobody can guess them.

Making strings…

Random keys and tokens usually end up in a server's .env file. Need the server too? From €3.02 a month today, among 2,226 servers.

Works in your browser: nothing you type is sent anywhere.

How the random strings are made

Every character is picked on its own from the characters you chose, using crypto.getRandomValues, the browser's cryptographically secure random number generator, the same source used for encryption keys. A simple random number modulo the number of characters would make some characters slightly more likely; this page draws again whenever a random value falls in the uneven remainder, so every character has exactly the same chance. The strength of a string is measured in bits of entropy:

bits = length × log2(characters to choose from)

32 × log2(62) = 32 × 5.954 ≈ 190.5 bits

Each bit doubles the number of guesses an attacker needs. A prefix such as sk_ adds nothing, because it is the same in every string; leaving out look-alikes takes a little off, because there are fewer characters to choose from. Math.random(), which many quick generators use, is not secure: its output can be predicted from earlier values.

Example

A 32-character string of letters and digits has 62 choices for each character, so 32 × log2(62) ≈ 190.5 bits: far beyond guessing. 32 hex characters carry 32 × 4 = 128 bits, the same as 16 random bytes. Base64url uses 64 characters, 6 bits each, so 43 of them hold 258 bits, what 32 random bytes encode to. A 6-digit code has only a million possibilities (19.9 bits): in a list of 500 such codes, the chance that two are the same is already about 11.7%.

On the server

To make random strings on a Linux server or in a deploy script, use the system's secure random source, /dev/urandom, through openssl or tr:

shell
openssl rand -hex 16          # 32 hex characters
openssl rand -base64 32 | tr '+/' '-_' | tr -d '='
head -c 500 /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9' | head -c 32

Questions

Are these random strings secure?

Yes. They come from crypto.getRandomValues, your browser's cryptographically secure random number generator, and every character is drawn without bias. They are made on your device and never sent to a server, so nobody else sees them. For keys and tokens, use at least 128 bits of entropy, such as 22 letters and digits or 32 hex characters.

How do I generate a random 32-character string?

Set the length to 32, which is the default, and choose the characters: letters and digits give about 190 bits, hex gives exactly 128. On a server, openssl rand -hex 16 prints 32 random hex characters. In Python: secrets.token_hex(16), or secrets.token_urlsafe(24) for 32 Base64url characters.

How long should a random API key or token be?

At least 128 bits of entropy, so it cannot be guessed even with billions of tries a second. That is 22 letters and digits, 32 hex characters or 22 Base64url characters. Many services use 32 to 40 characters with a prefix such as sk_ that says what the key is for, which helps secret scanners find leaked keys.

What is the difference between hex and Base64url strings?

Hex uses 16 characters (0–9 and a–f), so each holds 4 bits. Base64url uses 64 (letters, digits, - and _), so each holds 6 bits and the string is a third shorter for the same strength. Both are safe in URLs, file names and config files. Hex is easier to read; Base64url is more compact.

Can two generated strings be the same?

With enough length, practically never: with 128-bit strings you would need around 2^64 of them, 18 billion billion, before a repeat became likely. Short strings repeat sooner than you might think, by the birthday problem: among 500 six-digit codes, two are the same about 12% of the time. The page warns you when a repeat in your list is likely.