HOW-TO

How to generate a random string

Generate a cryptographically random string for tokens, keys, and IDs. Free tool plus the secure one-liner in each language.

A random string is the building block for tokens, secrets, salts, and unique IDs. The key is to use a cryptographically secure source, not a predictable one. Here is how to generate a good one.

Use a secure random source

Never build "random" strings from timestamps, counters, or Math.random() for anything security-sensitive — they are predictable. Use a cryptographically secure generator. Our token generator does this; in code use crypto.randomBytes (Node), secrets.token_urlsafe (Python), or crypto/rand (Go).

Length and alphabet

Pick a length that gives enough entropy — 32 characters from a large alphabet is a strong default for tokens and secrets. For values that go in URLs, use a URL-safe alphabet (letters, digits, - and _) so you do not need extra encoding.

Step by step

1

Open the token generator and choose your length (32+ for secrets).

2

Generate and copy the string.

3

In code, prefer crypto.randomBytes / secrets.token_urlsafe / crypto/rand — never Math.random for secrets.

4

Use a URL-safe alphabet if the value goes into a URL.

Try it now — free, no signup

Use the token generator in your browser. Then, when you need it at scale with an API key and higher limits, grab the full Eveses API.

FAQ

Is Math.random good enough?›
No — it is predictable and unsafe for secrets. Use a cryptographically secure generator.
How long should a random string be?›
At least 32 characters for tokens and secrets, so it cannot be brute-forced.

Related