The random open port provides some helpful functionality for getting a random port that isn't tracked identified as a known port in https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Registered_ports.
pip3 install random-open-port
Python 3+
Simply run
foo@bar:~$ random-port
Random Port: 36952
from random_open_port import random_port
port = random_port()
from random_open_port import get_taken_ports
taken_ports = get_taken_ports()
from random_open_port import get_wiki_ports
wiki_ports = get_wiki_ports()
from random_open_port import read_ports_file
cached_ports = read_ports_file()