Home › Developer Tools › Random String Generator

Random String Generator

Create random strings for tokens, test data, coupon codes or IDs. Every character comes from your browser's cryptographic random generator with rejection sampling, so no character is more likely than another.

Last updated:

Characters
Entropy per string–
Pool size–
Possible strings–

Advertisement
Advertisement

How to use the Random String Generator

  1. Pick a preset or tick the character sets you want, and add custom characters if needed.
  2. Set the length and quantity. Up to 10,000 strings can be created at once.
  3. Choose options: exclude look-alike characters, require every set, make all strings unique or add a prefix and suffix.
  4. Press Generate Strings and check the entropy figure to see how hard the strings are to guess.
  5. Copy or download the list as a text file.

Entropy by length and character set

Entropy measures how many guesses an attacker needs: a string with b bits takes up to 2b guesses. Entropy = length × log2(pool size).

Character setPool sizeBits per char16 chars22 chars32 chars
Numeric 0–9103.32253.273.1106.3
Hex 0–9 a–f164.00064.088.0128.0
Letters a–z A–Z525.70091.2125.4182.4
Alphanumeric625.95495.3131.0190.5
Base64url (A–Z a–z 0–9 - _)646.00096.0132.0192.0
All printable ASCII946.555104.9144.2209.7

Why rejection sampling matters

A random 32-bit integer has 4,294,967,296 possible values. For a 62-character alphabet, 4,294,967,296 ÷ 62 leaves a remainder of 4, so with the shortcut x % 62 the first four characters would each appear once more out of every 4.29 billion draws. The bias is tiny here but grows with larger alphabets or smaller random numbers (one random byte with % 62 makes the first 8 characters 25% more likely than the rest).

This generator computes limit = 232 − (232 mod N), throws away any value at or above the limit and draws again. Every accepted value maps to exactly the same number of characters, so the output is perfectly uniform. On average fewer than one draw in a billion is rejected for typical alphabets.

Requiring one character from each set

Many systems demand "at least one digit and one uppercase letter". The tool meets this rule by drawing whole strings and rejecting those that miss a set, which keeps every valid string equally likely. The number of valid strings is counted exactly with inclusion–exclusion. Example for length 2 with uppercase (26) and digits (10): 36² − 26² − 10² = 520 valid strings, or log2(520) = 9.02 bits instead of 10.34.

Typical uses and suggested settings

UseSuggested settingEntropy
Session ID or CSRF token32 alphanumeric190 bits
URL-safe token22–43 Base64url132–258 bits
Coupon or invite code8–10 uppercase + digits, no look-alikes40–50 bits
Test data / placeholder IDs12 lowercase hex48 bits
One-time numeric PIN6 digits19.9 bits (rate-limit attempts)

Frequently asked questions

Are these random strings secure?

Yes. They are generated with crypto.getRandomValues, the browser's cryptographically secure random number generator, which is suitable for tokens, session IDs and secret keys. Math.random is never used.

What is modulo bias and how is it avoided?

Mapping a random 32-bit number to an alphabet with value % size makes the first characters slightly more likely whenever 2^32 is not a multiple of the alphabet size. This tool discards random numbers above the largest multiple of the alphabet size and draws again (rejection sampling), so every character has exactly the same probability.

How is entropy calculated?

For a string of length L drawn from N possible characters, entropy = L × log2(N) bits. A 32-character alphanumeric string (N = 62) has 32 × 5.954 = 190.5 bits. If you require one character from each set, the tool counts the valid strings exactly with inclusion–exclusion, which gives a slightly lower figure.

How long should a random token be?

128 bits of entropy is the usual target for secrets and session tokens: 22 alphanumeric characters, 32 hex characters or 22 Base64url characters. For short codes that people type, fewer bits are fine as long as attempts are rate-limited.

Can I make sure no two strings are the same?

Tick “All strings unique”. The generator then skips duplicates. If you ask for more strings than are possible with the chosen length and characters, it tells you instead of looping forever.

Are the strings stored or sent anywhere?

No. Everything is generated on your device and nothing is uploaded or saved, apart from your option choices, which are remembered in your browser.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Password GeneratorCreate strong passwords and passphrases.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Hash GeneratorGenerate MD5, SHA-1, SHA-256 and SHA-512 hashes of text or files.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.Alternating Caps GeneratorTurn text into aLtErNaTiNg caps, random caps or alternating words, then copy it.Argon2 Hash GeneratorHash passwords with Argon2id, Argon2i or Argon2d and verify them against an encoded hash.TOTP GeneratorGenerate 2FA one-time codes from a secret key, create otpauth QR codes and verify codes.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.Docker Run to Compose ConverterConvert docker run commands to docker-compose.yml, or a compose file back to docker run.Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nano ID GeneratorGenerate secure Nano IDs with custom alphabet, length and count, plus a collision calculator.Nginx Config GeneratorBuild an nginx server block: static site, SPA, reverse proxy or PHP, with SSL, gzip and redirects.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.Docker Compose ValidatorCheck a docker-compose.yml for YAML errors, schema mistakes, broken references and deprecated keys.Dockerfile LinterLint a Dockerfile for best practices: pinned tags, apt cleanup, non-root USER and layer count.Dockerignore GeneratorBuild a .dockerignore from Node, Python, Go and Java templates, plus your own entries.ESLint Config GeneratorGenerate a flat eslint.config.js for JavaScript, TypeScript, React or Node with rule presets.Git Branch Name GeneratorTurn a ticket ID and title into a clean, valid git branch name like feature/PROJ-12-add-login.GitLab CI Config GeneratorGenerate a .gitlab-ci.yml with stages, jobs, images, cache, artifacts and rules from templates.Jinja2 Template TesterRender Jinja2 templates with YAML or JSON variables using real Jinja2, with clear error lines.JSON Schema Mock Data GeneratorGenerate realistic sample JSON from a JSON Schema: formats, patterns, $ref, seeds and counts.Kubernetes Secret GeneratorCreate Kubernetes Secret YAML from key/value pairs or .env with auto base64, or decode one.Kubernetes YAML ValidatorValidate Kubernetes manifests against the API schema of a chosen version, with error paths.Prettier Config GeneratorToggle Prettier options, preview formatted code live and copy your .prettierrc file.Quartz Cron GeneratorBuild and explain Quartz and Spring cron expressions with seconds, ?, L, W and #, plus next fire times.README Badge GeneratorCreate Shields.io-style README badges for license, version, build and custom labels.Systemd Service File GeneratorCreate a systemd .service unit with ExecStart, user, restart policy, environment and hardening.tsconfig.json GeneratorBuild a tsconfig.json with target, module, strict checks and path aliases, each option explained.Access Log AnalyzerAnalyze Apache and Nginx access logs: top URLs, IPs, status codes, bots and traffic charts.Regex String GeneratorGenerate random test strings that match any regular expression, checked against the real regex.ASCII Table GeneratorTurn CSV or pasted cells into plain-text tables: MySQL, Markdown, Unicode box and reST styles.Dummy File GeneratorCreate test files of an exact size in KB, MB or GB with zeros, random bytes or text.FFmpeg Command GeneratorPick a task and options, get the exact ffmpeg command with every flag explained.Folder Tree GeneratorTurn a local folder or an indented list into an ASCII directory tree for your README.GitHub Actions Workflow GeneratorBuild a GitHub Actions CI workflow: triggers, matrix, caching, tests, Pages or Docker deploy.Kubernetes YAML GeneratorGenerate Deployment, Service, Ingress, ConfigMap, Secret and HPA manifests with safe defaults.Markdown TOC GeneratorGenerate a linked table of contents from Markdown headings with GitHub-style anchors.OpenAPI EditorEdit OpenAPI/Swagger YAML or JSON side by side with live API docs, validation and download.OpenAPI ValidatorValidate OpenAPI 3.0/3.1 and Swagger 2.0 specs: schema errors, broken $refs, line numbers.Pivot Table MakerBuild pivot tables from CSV or Excel by drag and drop: sum, count, average, charts, export.SQL Query BuilderBuild SELECT queries visually: joins, filters, GROUP BY, ORDER BY and LIMIT, as clean SQL.Truth Table GeneratorType a logic expression and get its full truth table, minterms and canonical DNF/CNF.TypeScript PlaygroundWrite TypeScript with live type checking, see the compiled JavaScript and run it in your browser.
See all 85 Code Generators & Builders →