Mathematical Explanation:
To determine the time required to reach a
1% probability of at least one collision when generating NanoIDs, we use the following mathematical formula derived from the birthday paradox:
Formula:
n = √(-2 × N × ln(1 - P))
Where:
n
= Total number of IDs needed to reach the target probability.
N = ak
= Total number of possible unique IDs, where a
is the alphabet size and k
is the ID length.
P
= Target collision probability (in this case, 0.01
for 1%).
ln
= Natural logarithm.
By rearranging the formula, we can solve for
n
, and subsequently determine the time required based on the rate of ID generation.
Example Calculation:
If you have an alphabet size of
64
characters and an ID length of
21
, the total number of possible unique IDs
N
is:
N = 6421 ≈ 1.20892582 × 1038
To reach a
1%
collision probability:
n = √(-2 × 1.20892582 × 1038 × ln(0.99)) ≈ 1.555 × 1018
If you generate
1,000
IDs per hour, the time
t
required is:
t = n / rate = 1.555 × 1018 / 1,000 = 1.555 × 1015 hours ≈ 176,136,364 Years
Note: This calculation assumes that each ID is generated independently and that the probability of generating the same ID multiple times remains constant throughout the generation process.