[Q]:Generate Unique ID's

Uwe Schmitt uwe.schmitt at procoders.net
Sat May 24 19:06:41 EDT 2003


achrist at easystreet.com wrote:
> I'd like to generate unique identifiers for database items,
> sort of like the ID's that MS uses for COM.  My purpose is 
> to have unique ID's (across multiple [distributed] installations of
> a program), so that databases can be combined, copied, carried off,
> re-acquinted, compared, re-synchronized, etc, with some prayer
> of not being totally munged.

> 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?  How 
> about an easy call to Windows (if I don't care about cross-platform)
> to have it generate one for me?  As this might happen every time
> a user presses enter, maybe even several times on some updates, 
> it would be nice if it never took more than (e.g.) 0.1 secs or so.

I use something like:

import md5, time

m = md5.md5()
m.update("myname%s" % time.time())
res = m.hexdigest()
m.update("myname%s" % time.time())
res += m.hexdigest()

You can use your ip-adress/mac-adress/.... instead of 'myname'.
The result should be 'very' unique.


Greetings, Uwe.


-- 
Dr. rer. nat. Uwe Schmitt   http://www.procoders.net                      
schmitt at procoders.net      "A service to open source is a service to mankind."




More information about the Python-list mailing list