Generating a unique identifier

Paul Rubin http
Fri Sep 7 17:42:45 CEST 2007

Steven D'Aprano <steve at> writes:
> def unique_id():
>     n = 1234567890
>     while True:
>         yield n
>         n += 1

unique_id = itertools.count(1234567890)

> which is easy enough, but I thought I'd check if there was an existing 
> solution in the standard library that I missed. Also, for other 
> applications, I might want them to be rather less predictable.

def unique_id():
   return os.urandom(10).encode('hex')

More information about the Python-list mailing list