I will defer to Tony, but I think we can still do this without allocating a big array, randomly reshuffling it and then picking numbers from it. Randomly jumping to a point in that range and incrementing from there (with wrapping) has the desired effect of (a) not choosing the same port every time and (b) not retrying the same port repeatedly.