Tony decided that algorithm should be:
1) try to bind to 53843 (CommandConstants::BASE_INSTANCE_AGENT_SOCKET_PORT)
2) On failure, choose a new random port in the range (49152..65535)
3) Retry #2 until bind is successful
We could use something like 49152 + rand(65535-49152) for step 2, but this variant not so obvious as current(also there is tiny probability to try with the same port twice ;)).