By · Updated

Random String Generator

Cryptographically Secure Random Strings in Hex, Base64, URL-Safe or Custom Character Sets

No ratings yet

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the Random String Generator works

This random string generator draws from the character sets you choose. Generate one or many random strings of exactly the length you need, drawn from the character set you choose. Every character comes from your browser's cryptographic random number generator, so the output is suitable for API keys, session tokens, salts and nonces as well as for test fixtures.

Random string generator: length and entropy

A random string is the raw material behind most secrets in software: the API key a service hands out, the token in a password-reset link, the salt stored beside a hash, the nonce that makes a request unique. It is also the quickest way to make a placeholder that no real value could collide with. The two things that matter are that the characters are genuinely unpredictable and that the set they are drawn from suits where the string will be used.

Randomness. Everything here comes from crypto.getRandomValues, the browser's interface to the operating system's cryptographic generator — the same source used for TLS keys. It is not Math.random, which is seeded predictably and must never be used for secrets. Characters are selected by rejection sampling so each one is exactly as likely as any other; the naive "random number modulo alphabet size" approach quietly favours the first few characters of the alphabet, and that bias is avoided here.

Character sets. Alphanumeric (62 characters) is the general-purpose choice and gives about 5.95 bits of entropy per character. Lowercase and digits suits identifiers that will be lower-cased or used in hostnames. Hex gives 4 bits per character and matches what many libraries expect for secrets and salts — a 64-character hex string is a 256-bit key. Base64 and URL-safe base64 pack 6 bits per character; the URL-safe variant swaps + and / for - and _ so the string survives a query string or a filename. Alphanumeric and symbols adds common punctuation for maximum density. Custom lets you type any characters you like — paste an alphabet with no look-alikes, a set of emoji, or just ACGT.

How long? Think in bits, not characters. A string is unguessable when its entropy is around 128 bits, which is 22 alphanumeric characters, 32 hex characters or 22 base64 characters. The stats line beneath the output shows the entropy for your chosen length and set so you can size a token properly instead of guessing. Test data and short IDs can be much shorter; nothing here enforces a minimum.

Several at once. Set How many to generate a batch, one per line, for seeding a database or issuing a set of keys. Each string is independently random; there is no sequence to extrapolate from one to the next.

Where the output goes. Nowhere. The strings are created in your browser tab, are not sent to a server or logged, and vanish when you leave the page. Copy what you need and treat it like any other secret from that moment on.

FAQ

Is this secure enough for API keys and tokens?

Yes. The characters are drawn from the operating system's cryptographic generator via crypto.getRandomValues, with unbiased sampling, and never leave your browser. A 32-character alphanumeric string carries around 190 bits of entropy, well beyond what any brute-force attack could cover.

How long should a token be?

Aim for at least 128 bits of entropy: 22 alphanumeric, 32 hex or 22 base64 characters. Many systems use 32 or 64 characters for comfortable margin. The entropy stat under the output updates as you change the length and character set so you can check.

Why avoid Math.random for this?

Math.random is designed for speed, not secrecy. Its internal state is small and, in several engines, has been recovered from a handful of outputs, which lets an attacker predict every value that follows. The cryptographic generator has no such weakness and is just as easy to call.

What does the custom character set accept?

Any characters, including emoji and other multi-byte characters. Each distinct character in the box is one symbol in the alphabet; duplicates are removed so they do not skew the odds. The entropy figure reflects the actual number of distinct characters you supplied.

See also: all Security & Identifiers tools, Dev Utilities, Formatters & Validators, Data & Encoding, SEO, Accessibility, AI.

Related tools