Run a command to randomly select a port number between 10000 and 65535 and then use that port number to check if it is open on localhost.
shuf -i 10000-65535 -n 1 | xargs printf "nc -z -v -n %s  localhost"