Hacker News new | ask | show | jobs
by adrae5df 3864 days ago
Can someone explain how the following calculation was done?

With 2¹³² possible values, if identifiers were randomly generated at the rate of one million per second for the next 300 years the chance of a collision would be roughly 1 in six billion.

I tries using the formula for the Birthday problem, but the values are too large.

2 comments

Which formula did you use? There are various approximations.

Although I got ~43 years using the one from https://en.wikipedia.org/wiki/Birthday_attack#Source_code_ex...

  julia> birthday(prob, vals) = sqrt(2 * vals * -log1p(-prob))
  birthday (generic function with 1 method)
  
  julia> iters = birthday(1/6e9, 2.0^132)
  1.3471597122821932e15

  julia> iters / 1e6 / 60 / 60 / 24 / 365
  42.718154245376496
I found an approximation (x^2/2m) and got the result that is on the same magnitude as 1 in a billion.
I'm not sure about their numbers, but with a little trick it can be estimated as 1-e^(-2^(n-x-1)), where x is the number of bits and n is log_2 of the number of random draws. When n and x are relatively close, you should be able to calculate this without numbers getting too big or too small.