Random Port Generator
Draw unique random ports for tests and throwaway services — skip well-known and commonly-used ports so collisions stay unlikely.
Examples
Five ports for mock servers
count 5 · range 1024–65535 · both exclusions one.g. 13871, 22440, 39505, 41887, 59219 — unique, sorted, no well-known or common-service portsStart your mocks on any of these without worrying about Postgres, Redis or a forgotten dev server.
Ephemeral-only draw
count 10 · range 49152–65535 · well-known filter moot10 unique ports all ≥ 49152The OS hands this range out for temporary connections, so static services rarely sit here.
Rejected draw
count 100 · range 1024–1100 · common services onerror: filters leave only N ports — lower the count or relax the exclusionsValidation refuses impossible draws instead of returning duplicates or a silent partial list.
About this tool
Ports are the sixteen-bit door numbers of the internet — 0 through 65535 — and the space is divided into three territories with very different rules. The well-known range 0–1023 holds the classics (80 for HTTP, 443 for HTTPS, 22 for SSH) and is privileged: binding there requires administrator rights. The registered range 1024–49151 is where application vendors have claimed their slots (3306 for MySQL, 5432 for PostgreSQL, 6379 for Redis, 8080 as the universal HTTP-alt), and the dynamic or ephemeral range 49152–65535 is the space operating systems hand out for temporary outbound connections. The Random Port Generator draws from whichever slice you point it at, with the defaults aimed at the registered range where a random pick is both bindable and unlikely to collide.
The problem with naively picking "a random port" is that randomness alone doesn't avoid collisions. A uniform draw over 1024–65535 has a small but real chance of landing on 3306 or 5432 or the dev server you forgot was still running — and then your test fails with EADDRINUSE for reasons that look mysterious. This tool ships a bundled list of roughly two hundred ports that real services and development tools actually listen on: the classic infrastructure services, the database defaults, the message brokers, the monitoring endpoints, and the de-facto development ports (3000 for Node and Rails, 4200 for Angular, 5173 for Vite, 9229 for the Node inspector). One checkbox removes the whole list from the draw; another removes the well-known block; and a collision-risk badge tells you honestly which level of protection you have — low with both filters, moderate with one, higher with none.
The randomness itself is done properly: every port comes from crypto.getRandomValues using rejection sampling, which guarantees a uniform distribution with no modulo bias — the subtle skew that Math.random() % range solutions produce. Uniqueness is enforced structurally, not by hope: the generator draws until it has the exact count of distinct ports you asked for, up to 100, and validation rejects option sets whose filters leave fewer candidates than the count, so you can never receive duplicates or a partial list by surprise. Results come back sorted ascending, one per line, ready to paste into a script, a Docker compose file, a pytest fixture or a CI matrix.
Equally important is what the tool does not do: it never probes, scans or checks your machine. Port scanning other people's systems is hostile and often illegal, and even scanning localhost would require network permissions this page deliberately lacks — generation is pure math on locally generated random numbers with zero network calls. That makes it a legitimate complement to tools that do check real availability: pick a candidate here, then confirm it binds cleanly with your own server or a network tool. For actually finding free ports in production code, prefer asking the OS directly (bind port 0 and read the assigned port); a generator like this is for choosing stable, human-managed port assignments — test configs, service defaults, documentation examples — where you need numbers that are both predictable in the file and unlikely to clash in the world.
What this tool does not do
- Generates numbers only — it never probes or scans, so availability must be confirmed by actually binding the port.
- The common-service exclusion list is a curated ~200-entry subset of IANA assignments plus de-facto dev ports, not the full registry.
- Draws are unique within one generation; two separate generations can share ports by design.
How to use this tool
Choose the count
Enter 1–100 ports. The count persists between visits, so a daily workflow keeps its usual number.
Set the range
Defaults to 1024–65535. Point it at 49152–65535 for the ephemeral block, or any custom slice — bounds are validated.
Pick exclusions
Skip well-known (0–1023) and/or the bundled ~200 common-service ports. The collision-risk badge reflects your combination.
Generate and copy
Ports arrive unique and sorted ascending, one per line — copy the list straight into scripts, compose files or CI matrices.
Use cases
Local test fixtures
Pick stable-but-safe ports for mock servers and integration fixtures so suites don't fight Redis or Postgres for 5432.
CI matrix coordination
Generate one port list per shard; uniqueness and exclusions keep parallel jobs from binding the same port.
Documentation and defaults
Choose example ports for READMEs and compose files that readers can actually bind on their own machines.
The three port territories
| Range | Character |
|---|---|
| 0–1023 (well-known) | Classic services (80 HTTP, 443 HTTPS, 22 SSH); privileged binding — excluded by default |
| 1024–49151 (registered) | Vendor claims (3306 MySQL, 5432 PostgreSQL, 6379 Redis, 8080 HTTP-alt); default draw range |
| 49152–65535 (dynamic/ephemeral) | OS-assigned temporary ports; least likely to have static services bound |
The bundled exclusion list covers ~200 registered-range services plus de-facto dev ports (3000, 4200, 5173, 9229, 27017…).
Common mistakes
Mistake:Assuming a generated port is free.
Fix:Generation is math, not discovery — nothing is probed. Bind the port (or check with a network tool) before relying on it; for production code prefer binding port 0 and letting the OS assign.
Mistake:Picking from the well-known range for local services.
Fix:Ports 0–1023 are privileged (binding needs admin rights) and reserved for classics. Keep the well-known filter on unless you specifically need one of them.
Mistake:Using Math.random() % range in your own tooling.
Fix:Modulo on a random integer skews the distribution. This generator uses crypto.getRandomValues with rejection sampling — copy that approach, or reuse the tool's output wholesale.
Frequently asked questions
What port ranges should I generate from?
The default 1024–65535 is the practical sweet spot: it avoids the privileged well-known block (0–1023) where binding needs administrator rights, and it's where custom services are expected to live. Inside it, 49152–65535 is the dynamic/ephemeral territory that operating systems use for temporary connections, so nothing static is usually bound there. Keep the common-service filter on if your ports must not collide with databases, dev servers or infrastructure like MySQL (3306), PostgreSQL (5432) or Redis (6379).
Does the tool check whether the generated port is actually free?
No — deliberately. Generation is pure local math on crypto.getRandomValues with zero network activity: nothing is probed, scanned or uploaded, which also keeps it legal and safe, since scanning other systems' ports is hostile territory. Treat the output as strong candidates: bind one in your server to confirm, and if you need a guaranteed-free port in code, bind port 0 and read the port the OS assigns. The generator is for stable, human-managed assignments like test configs and documented defaults.
How does the common-service exclusion list work?
It's a bundled list of roughly two hundred ports that real software actually listens on: IANA classics (80, 443, 22, 53), database defaults (3306, 5432, 27017), message brokers (5672, 9092), monitoring endpoints (9090, 9100), and de-facto development ports (3000, 4200, 5173, 9229, 8080). When the filter is on, any draw landing on one of those numbers is rejected and redrawn. It's a curated subset rather than the full registry — enough to dodge everything you're likely to have running — and the collision-risk badge reflects exactly which filters are active.
Are the generated numbers truly random and unique?
Random: every port comes from crypto.getRandomValues with rejection sampling, so the distribution is uniform with no modulo bias — the flaw in the common Math.random() % range pattern. Unique: the generator keeps a set and redraws on duplicates until it reaches your count, so a request for 100 ports returns exactly 100 distinct numbers, sorted ascending. If your exclusions and range leave fewer than the requested count of candidates, validation refuses the draw with a clear error instead of returning duplicates.
Why avoid port 3000, 8080 and other dev defaults for my own services?
Because real software is already sitting on them: 3000 is the default for Node, Rails and Next.js dev servers, 8080 is the universal HTTP-alt, and 27017 is MongoDB. Binding your test service there means a forgotten dev process produces a confusing EADDRINUSE — or worse, your test talks to the wrong server that happens to be running. Generating from the same range with the common-service filter on keeps your human-chosen ports out of that blast radius, which is exactly what the exclusion list encodes.
How many ports can I generate at once?
Between 1 and 100 per draw. The limit keeps the output a paste-ready list rather than a data dump, and the uniqueness guarantee holds across the whole draw — you can request 100 distinct ports from a range of thousands without issue. If you need more, generate in batches with different ranges, or have your code assign ports dynamically at runtime by binding port 0; the generator's output format (one port per line) makes it easy to concatenate multiple batches in a file.