Platform-independent GUID creation?

Leeuw van der, Tim tim.leeuwvander at nl.unisys.com
Thu Jan 10 10:09:02 CET 2002


Hello,

I missed most of the thread, but the method I recently concocted for getting
unique session identifiers is:

import time
import random

def generateSessionID(self):
    """Attempt to generate a unique, random number or string, 32 positions
long"""
    str = '%011d%010d%011d' % (long(random.random() * 100000000000L),
                              long(time.time()),
                              long(random.random() * 100000000000L))
    return str


It won't generate Globally unique Id's, but I need them to be unique just to
my machine, and not sequential.

I don't know how this matches with the previously posted method, as I missed
that posting, and I don't know how well it will actually work in the real
world. So I give no guarantees, but anyone is welcome to apply it where they
want ;-)

--Tim

Toby Dickenson <tdickenson at devmail.geminidataloggers.co.uk> wrote:

> 
> "Irmen de Jong" <usenet at NOSPAM-irmen.cjb.net> wrote:
> 
> >I don't have a better solution. If anybody has a better (Pythonic) GUID
> >generator, I'd be very interested.
> 
> On machines that have it, /dev/urandom may well be unique enough.

As you say already, it's not platform-independant...

> 
> Toby Dickenson
> tdickenson at geminidataloggers.com
> 





More information about the Python-list mailing list