Skip to content
ToolkitHub

Random String Generator

Generate random strings

Guide

Random strings, character sets and entropy

By Logappradeep · ServiceNow developer

Random strings are everywhere in software: test fixtures, placeholder IDs, sample usernames, temporary file names, coupon-style codes, cache-busting values, and API keys for local development. This generator builds strings from 1 to 4,096 characters long, up to 1,000 at a time, using the character sets you choose. A fresh batch is generated whenever you change the options.

Choosing a character set

  • Uppercase A–Z (26 characters)
  • Lowercase a–z (26 characters)
  • Numbers 0–9 (10 characters)
  • Symbols: ! @ # $ % ^ & * ( ) _ + - = [ ] { } | ; : , . < > ? (26 characters)

The default combination of letters and digits gives a 62-character alphabet, the same one used by many short-ID schemes. Turn symbols on when a system requires them, and off when the string will appear in URLs, file names, shell commands, CSV files, or anything a person has to read aloud.

How much randomness is enough?

The strength of a random string is measured in bits of entropy: its length multiplied by the base-2 logarithm of the alphabet size. Some reference points:

  • Digits only: about 3.3 bits per character.
  • Letters and digits (62 characters): about 5.95 bits per character, so 16 characters give roughly 95 bits.
  • Letters, digits, and the 26 symbols (88 characters): about 6.46 bits per character.

Each additional bit doubles the number of possible strings. For identifiers that only need to avoid collisions, 64 to 128 bits is typical, and for secrets such as API keys, 128 bits or more is a sensible floor. Adding length is generally more effective than adding symbol types: a 22-character alphanumeric string carries about 131 bits, more than an 18-character string that includes symbols.

Where the randomness comes from

Not all randomness is equal. JavaScript's Math.random() is designed for speed and statistical spread, not unpredictability, and must never produce security-sensitive values. This generator instead draws from the Web Crypto API's crypto.getRandomValues(), the browser's cryptographically secure random number generator. It also uses rejection sampling, which avoids the subtle modulo bias that makes some characters slightly more likely when random bytes are mapped onto an alphabet whose size does not divide evenly. Every character in the set is equally likely at every position.

Practical tips

  • Avoid ambiguous characters such as 0/O and 1/l/I in codes people will type from a screen or paper.
  • Escape symbols when placing strings in JSON, SQL, regular expressions, or shell commands, where characters like ", \, $, and | have special meaning.
  • Enforce uniqueness where values are stored if they must never repeat. Randomness makes collisions unlikely, not impossible, especially with short strings.
  • Need a standard format? Use the UUID Generator for 128-bit identifiers every database understands, or the Password Generator for passwords that must include each character type.

Strings are generated in your browser and are never sent to a server.

Frequently asked questions

Are these strings secure enough for API keys or tokens?

Yes, the randomness comes from the browser's cryptographically secure generator. Use at least 22 letters and digits (about 128 bits), and store the value securely.

How long should a random ID be?

For collision resistance, aim for about 64 to 128 bits of entropy, which is roughly 11 to 22 letters and digits.

Why should I avoid symbols?

Symbols often need escaping in URLs, shells, JSON, and CSV, and they are harder to type. Leave them off unless a system requires them.

Can two generated strings be the same?

It is possible but extremely unlikely for long strings. If uniqueness is required, enforce it with a unique constraint where the values are stored.