Skip to content

Commit cdfaf82

Browse files
committed
Randomize port search
1 parent 3896a32 commit cdfaf82

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

vec_inf/find_port.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ find_available_port() {
2828
local base_port=$2
2929
local max_port=$3
3030

31-
for ((port=base_port; port<=max_port; port++)); do
31+
# Generate shuffled list of ports; fallback to sequential if shuf not present
32+
if command -v shuf >/dev/null 2>&1; then
33+
local port_list
34+
port_list=$(shuf -i "${base_port}-${max_port}")
35+
else
36+
local port_list
37+
port_list=$(seq $base_port $max_port)
38+
fi
39+
40+
for port in $port_list; do
3241
if is_port_available $ip $port; then
3342
echo $port
3443
return

0 commit comments

Comments
 (0)