Platform-independent GUID creation?

Leeuw van der, Tim tim.leeuwvander at
Thu Jan 10 04:09:02 EST 2002


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
    str = '%011d%010d%011d' % (long(random.random() * 100000000000L),
                              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 ;-)


Toby Dickenson <tdickenson at> wrote:

> "Irmen de Jong" <usenet at> 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

More information about the Python-list mailing list