How to generate random port number on the command line

The following Linux shell command will generate a random port number between 1024 and 65535 (inclusive):

shuf -i 1024-65535 -n 1

Example:

$ shuf -i 1024-65535 -n 1
45508