Random String Generator: Secure Random Strings and Tokens

Generate random strings, tokens, codes, and keys with crypto.getRandomValues and bias-free rejection sampling. Pick character sets or an alphabet preset, require every set, force a unique batch, and see the real entropy for your settings. Everything runs on this page and nothing is sent or stored. For standard RFC 9562 identifiers, use the UUID Generator instead.

Preset, length, and count
Characters

Each distinct character counts once; repeats do not add weight. Typing here turns the set on.

Output shape

Prefix, suffix, and separators are fixed text: they add length but no entropy. Example shape with groups of 4: XXXX-XXXX-XXXX

Strength and odds

Alphabet size
–
Entropy per string
–
Bits per character
–
Possible strings
–
Any duplicate in this batch
–
Strings for a 1% duplicate risk
–

Adjust the settings to see a strength note.

Ready. Press Generate or Ctrl+Enter.

Results

No strings yet.

    Diagnostics

      How it works and limits

      • Random numbers come only from crypto.getRandomValues (32-bit words). Math.random is never used. If the Web Crypto API is missing, generation is disabled.
      • Each character index is picked with rejection sampling: 32-bit values at or above the largest multiple of the alphabet size are thrown away, so value % size has no modulo bias.
      • Entropy is length × log2(alphabet size). With "require each set" on, it is log2 of the exact number of qualifying strings, counted with inclusion–exclusion, so it is always a little lower.
      • Required sets are not pinned to fixed slots. The tool either redraws whole strings until every set appears or, when that would be rare, uses an exact counting sampler. Either way every qualifying string is equally likely.
      • Unique mode rejects repeats inside one batch. It refuses when you ask for more strings than can exist. It cannot know about strings you made earlier or elsewhere.
      • The base64url and Nano ID presets draw characters from those alphabets. They are not base64 encodings of bytes, so decoding them to an exact byte count is not guaranteed.
      • Characters are Unicode code points. Emoji built from several code points or letters with combining marks may be split. Byte length in UTF-8 can be larger than the character count.
      • The strength note describes guessing resistance for an attacker who knows your settings. It is not a guarantee, and a secret is only as safe as where you store it.
      • The list shows the first 100 strings. Copy all and Download include every string. Very large batches (millions of characters) can take a few seconds and a lot of memory.