Turns out, supplying a port of "0" to a java ServerSocket will select a random open port for automagically! I'm refactoring this code to do just that.