Generating unique numbers?

Ken Seehof kseehof at neuralintegrator.com
Fri May 31 20:37:23 EDT 2002


> > > Is there a good algorithm for generating unique numbers 
> > > (ints, specifically) that can be used as object identifiers?
> > 
> > id(x)
> 
> If you need IDs that are unique across
> - different Python processes
> - different machines
> id(x) won't work.
> 
> Irmen

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.

In other words, a perfect answer to your question is
unlikely without knowing the context.  For example,
I might assume that this is a client-server application
of some kind and each client is responsible for generating
unique integers.  Without knowing the context, I don't
know whether to suggest simply using a serial number
server (a solution that worked fine for me in a perhaps
similar situation).

Ken






More information about the Python-list mailing list