[Zope3-dev] randid()

Steve Alexander steve@cat-box.net
Fri, 22 Mar 2002 23:51:29 +0000


Jeremy Hylton wrote:
> Tim and I were talking about the randid() function yesterday
> afternoon.  It seems to have two serious problems if it's used for
> generated unique ids:
> 
>     - It's subject to the birthday paradox.  We should expect to see a
>       duplicate after 2**16 calls.

Occasional duplicates shouldn't be a problem. That's the price we pay 
for not needing to persistently store the next id in sequence.
The duplicates should be infrequent, so this shouldn't be a worry.


>     - It's not in the least bit thread safe.  Two threads executing in
>       parallel could get the same sequence of random ids.

That shouldn't be much of a problem, as you'd get a conflict error and a 
re-try.

Perhaps there could be one random number generator with a high-entropy 
seed per ZODB Connection?


> Is there any reason we can't replace its use in ObjectHub with a
> simple persistence counter?

I don't know. Obviously, there's less overhead if we can get random ids 
to work.l This has implications for its use in ZCatalog (+ ZEO too) in 
Zope 2. Any important change should be considered for backporting to zope 2.

--
Steve Alexander