[Q]:Generate Unique ID's

andrew cooke andrew at acooke.org
Sat May 24 15:25:52 EDT 2003


achrist at easystreet.com writes:
> My back-of-the envelope calculations, done without any envelope, 
> suggest that if you could generate truly random p=0.5 bits,
> then if you generate a trillion row database every second for
> a period of time equal to the current age of the universe, and give
> each row a 128-bit random ID, it's about even money whether or not
> a duplicate key error would occur once over all those databases
> over that time period.  

My calculations don't agree (have I made a mistake?)

As far I can see you'll get "birthday" collisions at around sqrt(n)
number of ids, where n is the maximum ID value (maybe I'm wrong
here?).  So 128 bit IDs can be used about 2**64 times before
collisions are important.  If a trillion is 10**12, and you generate a
database every second then you have:
>>> (2l**64 / 10l**12)
18446744L
seconds, or 
>>> 18446744.0 / (60*60*24*365)
0.58494241501775746
years.

That's about half a year, which is somewhat shorter than the age of
the universe(!).

Andrew

-- 
http://www.acooke.org






More information about the Python-list mailing list