def select_random_ports(n):
ports = []<EOL>for i in range(n):<EOL><INDENT>sock = socket.socket()<EOL>sock.bind(('<STR_LIT>', <NUM_LIT:0>))<EOL>while sock.getsockname()[<NUM_LIT:1>] in _random_ports:<EOL><INDENT>sock.close()<EOL>sock = socket.socket()<EOL>sock.bind(('<STR_LIT>', <NUM_LIT:0>))<EOL><DEDENT>ports.append(sock)<EOL><DEDENT>for i, sock in enumerate(ports):<EOL><INDENT>port = sock.getsockname()[<NUM_LIT:1>]<EOL>sock.close()<EOL>ports[i] = port<EOL>_random_ports.add(port)<EOL><DEDENT>return ports<EOL>
Selects and return n random ports that are available.