Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.ARPA Path: utzoo!watmath!clyde!burl!ulysses!ucbvax!tcp-ip From: tcp-ip@ucbvax.ARPA Newsgroups: fa.tcp-ip Subject: Re: 4.2bsd/rlogin/source port choices Message-ID: <9129@ucbvax.ARPA> Date: Wed, 17-Jul-85 15:40:54 EDT Article-I.D.: ucbvax.9129 Posted: Wed Jul 17 15:40:54 1985 Date-Received: Thu, 18-Jul-85 20:18:07 EDT Sender: daemon@ucbvax.ARPA Organization: University of California at Berkeley Lines: 47 From: imagen!geof@su-shasta.ARPA The choices that I suggested are all things that I have done in implementations of various protocols (which need to choose port numbers for the same reason TCP does), and that have worked well. I personally think that low bits of clocks are more random than pseudo-random number generators. To get a really random number from a PRNG, you have to seed it with a random number (egg or chicken?). The obvious thing to do is seed the PRNG with the clock. Hmm.... why don't you just use the clock...? Using a clock also makes sense from a more theoretical point of view. In most situations the times at which connection requests are made are much more like independent random variables than anything else that a program can get its hands on. Especially when you have a fast clock. Of course, any choice of port is actually put inside of a loop which makes sure that the port is Currently unique. You can't be sure of not choosing the same port twice Sequentially unless you have hardware that is stable across system crashes (hey, the clock is more likely to fit that criterion than anything else, isn't it...?). If "portChoice()" chooses a port number using whatever algorithm you have in mind (but "1023" is probably not a good algorithm), then you need one of the following program fragments (sometimes this fragment is embodied in the kernel, which is an excellent idea): i := portChoice(); while portInUse(i) do i := i + 1; or i := portChoice(); while portInUse(i) do i := portChoice(); The one to use depends on the nature of you portChoice() procedure. If it is based on a one second clock, then maybe the first program fragment is better. If it is based on a microsecond clock, then the two are probably equivalent, but I like the second better, perhaps for irrational reasons. In any event, if you have a good portChoice() algorithm, you will almost never go through the loop more than once, and if you often go through it more than twice, rewrite portChoice, because it isn't working as it should. - Geof