Generalized formula
There's a formula that estimates how many values of size S to generate to get a collision between two of them with probability P.
Variables:
- bits - how many bits in your data type.
- probability - target probability for the collision.
To get a collision, you have to generate around:
%7D)
Or in Python:
from math import sqrt, log
def how_many(bits, probability):
return 2 ** ((bits + 1) / 2) * sqrt(-log(1 - probability))
GUIDs
For GUIDs (128 bits), to get a collision with probability 1% (0.01),
you'll need:
In [2]: how_many(bits=128, probability=0.01)
Out[2]: 2.6153210405530885e+18
...around 2.6 * 10^18 GUIDs (that's 42 exabytes of GUIDs).
Note that this probability grows rapidly. No matter the number of bits, for 99.99% probability you'll need only 30x more GUIDs than for 1%!
In [3]: how_many(bits=128, probability=0.9999)
Out[3]: 7.91721721556706e+19
Int64
Same numbers, but for the int64 datatype:
In [4]: how_many(bits=64, probability=0.01)
Out[4]: 608926881
In [5]: how_many(bits=64, probability=0.9999)
Out[5]: 18433707802
For 1% collision probability you'll need 5 gigabytes of int64-s. Still a lot but compared to the GUIDs that is a much more comprehensible number.
It's the so called birthday problem - and in this Wikipedia article you can find more precise estimation formulas than this one.