Generate random port numbers, optionally avoiding the well-known range below 1024 โ handy for local dev servers, test fixtures, and docker-compose files where you want something other than 3000 or 8080. Everything runs in your browser.
Random Port Generator
Generate random TCP/UDP port numbers
What the generator does, exactly
Each click draws between 1 and 100 integers (5 by default). With Avoid well-known (<1024)
ticked, which is the default, every number is picked uniformly from 1024 to 65535 inclusive โ 64,512
possible values. Unticked, the range is 1 to 65535. The draw uses the browser's Math.random(),
which is fine here: a port number is not a secret, so there is no need for a cryptographic generator.
Nothing is sent over the network when you click Generate.
What it deliberately does not do:
- It does not test whether a port is free. A browser has no way to list local listeners.
- It does not skip registered ports such as 3306 (MySQL), 5432 (PostgreSQL) or 8080, or the ephemeral ranges your operating system uses for outgoing connections. Any number in the range can come up.
- It does not guarantee unique values within a batch โ duplicates are possible, if rare.
- There is no custom min/max field; the only range control is the well-known checkbox.
The arithmetic behind one draw
With the box ticked, the tool computes 1024 + floor(r ร 64512), where r is a
random number in [0, 1). Plugging in the extremes and a midpoint, run against the tool's own function:
r = 0โ 1024, the lowest possible outputr = 0.5โ 1024 + 32256 = 33280r = 0.999999999โ 65535, the highest possible output
Unticked, the formula becomes 1 + floor(r ร 65535), so r = 0 gives port 1.
Because the distribution is uniform, about half of all default draws (32768โ65535) land at or above
32768, which matters for the next section.
The three port ranges, and why the middle one is the useful one
IANA splits the 16-bit port space into three blocks (RFC 6335): system or well-known ports
0โ1023, user or registered ports 1024โ49151, and dynamic or private ports
49152โ65535. On Linux, a process needs root or the CAP_NET_BIND_SERVICE capability to bind
below 1024, which is the practical reason dev servers live above it.
The dynamic block is where operating systems pick the source port for outgoing connections โ but they
don't all agree on where it starts. Windows (since Vista) and macOS use 49152โ65535; Linux defaults to
32768โ60999. So a port that is perfectly safe on a Mac can sit inside Linux's ephemeral range. If your
service runs in a Linux container or CI runner and you pin it at, say, 41234, an unrelated outgoing
connection can occasionally be assigned that same local port and your server fails to start with
EADDRINUSE. The post on
"address already in use" and ephemeral ports
walks through that failure and the other two common causes with real command output.
Rule of thumb: for something you will hard-code in a config file, keep the result if it is between 1024 and 32767 and reroll otherwise. For throwaway test servers, binding to port 0 and letting the OS choose avoids the problem entirely.
Before you use the number
Make sure nothing already owns it, and that it isn't a port some tool you rely on expects. The port reference lists the common assignments (SSH on 22, DNS on 53, HTTPS on 443 and so on). If you need random integers for something other than ports, with your own bounds, the random number generator takes a custom range and can rule out repeats.
Frequently asked questions
Which port range is safest for a local dev server?
1024 to about 32767. Below 1024 you need root (or CAP_NET_BIND_SERVICE) on Linux, and from 32768 up you are inside the range Linux hands out for outgoing connections (32768-60999 by default), while Windows and macOS use 49152-65535. A dev server pinned inside an ephemeral range can occasionally collide with a client socket some other program opened. If this tool gives you something at 32768 or above for a long-lived service, click Generate again.
Does the tool check whether the port is free on my computer?
No. A web page cannot see which ports are listening on your machine, so the numbers are purely random. Check before you use one: lsof -iTCP:PORT -sTCP:LISTEN on macOS or Linux, ss -ltn 'sport = :PORT' on Linux, or netstat -ano | findstr :PORT on Windows. No output means nothing is listening there.
Can I get the same port twice in one batch?
Yes. Each number is drawn independently, so repeats are possible. With the default range (64,512 possible ports) and the maximum batch of 100, the chance of at least one duplicate is roughly 7%. Scan the list if you need distinct values.
Is a TCP port number different from a UDP port number?
They share the same 1-65535 numbering, but TCP and UDP keep separate tables, so a TCP listener on 5000 and a UDP listener on 5000 do not conflict. The numbers this tool generates work for either protocol.
Why does the tool never return port 0?
Port 0 is not a real destination. When a program binds to port 0, the operating system picks any free ephemeral port for it, which is often the better choice in tests: bind to 0, then read back the port you were given. The generator's lowest possible output is 1 (box unticked) or 1024 (box ticked).
Get weekly dev tools and tips