If your server is using a standard protocol which has already been allocated an official port number, then you should use the official port number.
If the server is using a non-standard protocol without an official port number, you should be using a port number from the range 49152-65535 which is designated: Dynamic and/or Private Ports.
IANA haven't specified which of the numbers to use for dynamic assignments and which to use for locally defined services. However your OS might. In case of Linux any port number dynamically assigned to clients connecting outwards will be taken from the range specified in /proc/sys/net/ipv4/ip_local_port_range
By default this range is 32768 61000
, so you need to avoid anything in that range or below. Port numbers above 61000 should be safe to use.
Usually you want a static port number in your configuration such that anybody who need to contact it from outside know which port number to contact. But you can choose a random number from the range and put that in your configuration file to make it a little less likely to be found by port scans or result in a conflict when you need to work with another service which had chosen a port number from the same range.
I usually use this command to pick a port number for any locally defined service:
echo $[61002+RANDOM%4532]