Generating unique numbers?

Ken Seehof kseehof at neuralintegrator.com
Fri May 31 22:28:57 EDT 2002


Jeff wrote:
> On Fri, May 31, 2002 at 05:37:23PM -0700, Ken Seehof wrote:
> > In the case of multiple computers, you would combine
> > the machine id with id(x).  If you are allowed long
> > integers or tuples or 64 bit integers, that's trivial.
> > You might have to be clever to get it into 32 bits
> > reliably.
>
> It seems very likely that there have been more than 2**32 distinct objects
> generated in runs of Python programs across all the computers on the 'net.
> In fact, it seems very likely that some machines have generated more than
> 2**32 distinct objects (across several processes and some time) since even
> a fairly modest machine can successfully execute 'range(2**24)'.  If you
> want to talk about internet-accessible machines and use their IP
> address as
> part of the key, you'll run into two problems.  First, many machines
> probably have the IP address "10.0.0.1", which is part of a reserved space
> that many people are encouraged to use by ISPs that use some form of NAT
> for their clients.  Second, even if you ignore this problem you are left
> with a space of 2**32 with some relatively small number of addresses that
> you know cannot be used (according to the old class-system of IP networks
> you can determine some number <2**25 of broadcast and network addresses),
> it seems unlikely that you could get a unique network ID into less than 31
> bits.  That'll give you 2**(31+24) unique objects that might exist
> at any one time.  But as I tried to imply above, it's likely that some
> machines will run at least 2**10 processes during their lifetime, giving
> 2**(31+24+10) IDs (probably some machines will run 2**10 processes per
> hour, which would be 1 hit per 3 seconds running Python as a CGI script).
> But now we've gotten to 65 bits of a unique id...
>
> Of course, this 65-bit space will be quite sparse, but somewhere there's a
> machine that will use up each of the allocated fields, so you can't shave
> much off.
>
> So I don't think you could do a unique object identifier in 64 bits, with
> the requirement that it be unique over all processes in all
> machines on the
> internet.
>
> Jeff

Which brings us right back to my assertion that the original question
cannot be answered adequately without knowing the context.  Presumably
if the application in question had the scope you are describing (we
don't even know if it's an internet application), VanL would have a team
of 40 expert programmers at $450K salaries solving the problem, so we are
off the hook :-)

- Ken Seehof







More information about the Python-list mailing list