Random String Generator — Custom Length & Character Set
Generate random strings with custom length, character sets (alphanumeric, hex, symbols). Bulk generation supported.
About Random String Generator — Custom Length & Character Set
Random String Generator creates cryptographically random strings with a fully configurable character set, including uppercase letters, lowercase letters, numbers, and symbols. Perfect for generating API keys, tokens, and test data.
How to Use
- 1Set the desired string length and choose which character types to include.
- 2Click "Generate" to create one or more random strings instantly.
- 3Copy the generated strings and use them as passwords, tokens, or test fixtures.
Features
- Cryptographically random output powered by the Web Crypto API
- Fully customizable length and character set
- Generate multiple strings at once in bulk
- No data stored or sent — generation is 100% client-side
Cryptographically Secure Random Strings
Not all random strings are created equal. Understanding the difference between cryptographically secure and non-secure randomness is essential when generating strings for security-sensitive purposes.
Cryptographic vs. Pseudo-Random Generation
Standard programming language functions such as JavaScript's Math.random(), Python's random.random(), and PHP's rand() produce pseudo-random numbers using deterministic algorithms seeded from a relatively small initial value. While they appear random, their output can be predicted if the seed or internal state is known. This makes them unsuitable for security-critical applications such as session tokens, password reset links, and API keys. Cryptographically secure pseudo-random number generators (CSPRNGs) draw entropy from operating system sources such as /dev/urandom on Unix-like systems and BCryptGenRandom on Windows, which accumulate unpredictable data from hardware events like network timing and keystroke intervals. This makes CSPRNG output computationally infeasible to predict. This tool uses window.crypto.getRandomValues() in the browser, which is backed by the OS CSPRNG and meets the security bar for generating tokens and credentials.
Character Set and Entropy
The security of a random string depends on two factors: length and character set size. Entropy is measured in bits and calculated as: entropy = length multiplied by log2(charset_size). A 32-character alphanumeric string using 62 characters (a-z, A-Z, 0-9) has approximately 190 bits of entropy, which is more than sufficient for any current security purpose. Adding symbols expands the character set to about 94 printable ASCII characters, increasing entropy to roughly 204 bits per 32-character string. For comparison, a 128-bit AES key provides 128 bits of security, and 128 bits of entropy is generally considered the minimum for long-term security. A 22-character alphanumeric string already exceeds 128 bits. Longer strings and larger character sets provide more entropy, but even a 16-character alphanumeric string at 95 bits is strong for session tokens given their short lifetimes.
Security Use Cases for Random Strings
Random strings serve a wide variety of security and functional purposes in web development and systems programming. Choosing the right length and character set for each use case ensures both security and compatibility.
API Keys and Access Tokens
API keys are long-lived credentials that identify and authenticate a client. They should be generated with at least 128 bits of cryptographic entropy — roughly 22 or more alphanumeric characters. A common format is a prefix that identifies the service or key type (such as "sk_live_") followed by a long random string, making keys easy to identify in logs and configuration files without compromising security. Avoid using sequential IDs, UUIDs alone (which are not secrets), or encoded user IDs as API keys since they do not provide the necessary entropy or unpredictability. Store API keys hashed (SHA-256) in your database, just like passwords — this way, a database breach does not immediately expose valid credentials. When an API key is issued, it should be shown to the user only once and never stored in plain text on the server.
Password Reset and Verification Tokens
Password reset tokens, email verification links, and one-time codes must be unguessable and single-use. Generate them with a CSPRNG using at least 128 bits of entropy (22 or more alphanumeric characters, or 32 or more hex characters). Store only a hash of the token in the database, not the raw value. Associate each token with a specific user ID and an expiration time, typically 15-60 minutes for password reset and 24 hours for email verification. When the user submits the token, compare it against the stored hash using a constant-time comparison function to prevent timing attacks. Immediately invalidate the token after successful use to prevent replay attacks. Never include these tokens in server logs or error messages where they could be exposed to parties other than the intended recipient.
Session IDs and CSRF Tokens
Session identifiers must be random enough that an attacker cannot guess a valid session by brute force. OWASP recommends at least 128 bits of entropy for session IDs. Modern web frameworks such as Express.js, Django, Laravel, and Rails generate cryptographically random session IDs by default, but if you are building a custom session system, use a CSPRNG such as crypto.randomBytes() in Node.js or os.urandom() in Python. CSRF tokens should be unique per session and per form submission, generated with a CSPRNG, embedded in forms as hidden fields, and verified on every state-changing request. A CSRF token does not need to be extremely long since 128 bits is sufficient, but it must be tied to the authenticated session and validated server-side on every mutation request.
FAQ
- Is this cryptographically secure?
- Yes. The tool uses window.crypto.getRandomValues() which provides cryptographically strong random values, not a weak Math.random().
- Can I exclude ambiguous characters like 0, O, l, 1?
- Yes. Enable the "Exclude ambiguous characters" option to avoid characters that look similar, which is useful for human-readable codes.
- What is the maximum length I can generate?
- You can generate strings up to several hundred characters long depending on the tool settings.
- How random are the generated strings?
- This tool uses the browser's cryptographically secure random number generator (window.crypto.getRandomValues()), the same API used for generating cryptographic keys. This is significantly more random than Math.random() and suitable for generating tokens, passwords, and session identifiers that require unpredictability. The randomness comes from the operating system's entropy sources (hardware noise, mouse movements, timing events).
- What character sets are available for random string generation?
- Common options include: lowercase letters (a-z), uppercase letters (A-Z), digits (0-9), and symbols (!@#$%^&*). You can typically combine any of these. For URL-safe tokens, use alphanumeric only (letters + digits). For passwords, include symbols for higher entropy. For database IDs or filenames, use alphanumeric without symbols to avoid escaping issues. The tool shows the entropy in bits based on your settings.
Found a bug or something not working as expected?
Report a bug →