Picking Ports for Local Tests Without Colliding With Postgres
November 19, 2026 · DevTools
Every local test stack starts with a port negotiation: the mock server needs one, Postgres already has 5432, Redis has 6379, the dev server has 3000, and choosing "8081" by hand has a way of colliding with the thing you forgot. The Random Port Generator draws unique port numbers on demand — 1 to 100 of them, in any range, with the ports that real services actually use excluded from the draw.
Randomness done right
Two details separate a correct random port picker from a naive one:
crypto.getRandomValueswith rejection sampling — the numbers are uniformly random with no modulo bias, which a simplerand() % rangecannot promise.- Guaranteed uniqueness — even at the maximum draw of 100, no port appears twice, so a 10-port CI matrix generated in one batch never binds the same port twice.
Results arrive sorted ascending, one per line — paste-ready for scripts, docker-compose files, and CI configuration.
The exclusions are the feature
Three filters shape the draw:
- Well-known 0–1023 — the privileged block; skipped unless you say otherwise.
- ~200 common service ports — a bundled list of the ports that dev machines and servers actually listen on: 3000, 3306, 5432, 6379, 8080, 9200, 27017 and their neighbors. This is the list that saves you from the "forgot about Elasticsearch" class of collision.
- Your range — defaults to 1024–65535, but the ephemeral block 49152–65535 is one edit away when you want the territory where the OS is least likely to have anything bound.
A collision-risk badge states honestly how likely each generated port is already bound on your machine: low with both filters on, moderate with one off, higher unfiltered — because a random draw cannot know what your laptop is running, only reduce the odds and say so.
A use case per habit
- Mock server: draw 5 ports above 1024 with common services skipped — start the mock on one without stepping on your real databases.
- CI shards: each parallel job generates its own batch from the same range; uniqueness plus exclusions keeps shards from fighting over ports.
- Docker Compose: paste the sorted list straight into environment variables or port mappings.
Generation is purely local: the tool never probes or scans your machine, makes no network calls, and the picked ports never leave the page — it works offline, which is sometimes the point.
For the reference side of ports — what 5432 and 6379 actually are — the Port Reference lists the assignments, and the API Mock Server is where those freshly drawn ports usually end up working.