[Q]:Generate Unique ID's

Erik Max Francis max at alcyone.com
Fri May 23 20:40:53 EDT 2003


achrist at easystreet.com wrote:

> Is there anything in the standard Python libs to generate an ID
> like those that Windows uses, which are guaranteed to be unique
> over all instances of everything, forever, no exceptions?

There's really no such thing; with a finite ID size (e.g., 128 bits),
you're guaranteed that _eventually_ there will be a collision; the
question is simply whether or not it is remotely possible this could
happen in any remotely reasonable timescale.

I released PyUID, which is an extensible framework for generating unique
IDs (though not UUIDs), though it focuses on Unix-like operating
systems:

	http://www.alcyone.com/pyos/uid/

With a little knowledge of your problem domain, it's possible that it
might be feasible to come up with an ID generation scheme that truly
guarantees uniqueness (whether that applies to you I can't say).  Short
of that it is quite reasonable, with sufficient care, to come up with
IDs that are likely to be so unique that worry about a possible
collision is nil.  (There are no known concrete input data sets that
cause MD5 hash collisions, for instance, so the problem effectively
decays to guaranteeing that the input data is unique.)

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Convictions are more dangerous enemies of truth than lies.
\__/  Friedrich Nietzsche




More information about the Python-list mailing list