🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.privacy.anon-server
Article #7836

Re: Uniqueness of Key ID

#7836
From: Martin Harvey
Date: Tue, 07 Sep 1999 00:00
141 lines
4982 bytes
Peter Buzanits wrote:
> 
> The key-id is 32 bits long.
> 
> So if I did not calculate wrong, the probability, that the ids of
> approximately 1 million Keys are different (unique) is
> 
> p = ((2**32-1)/(2**32)) ** (2**20)

Your answer is about right for small numbers of keys, say less than one
thousand. For larger numbers of keys it becomes very bad very fast. I
kid you not... for a million keys, the actual chance of one million
unique keys is a factor of 10 to the power of 100 less than your formula
would suggest!

> Can anyone calculate that? (I have no software, that can do that...)

Hmm... well if you want to calculate it, then you'll have to be careful
to avoid numerical inacuracies... Luckily, your first approximation is
sufficiently simple that an exact answer can be calculated for it, and
thus we can estimate the innacuracies. Basically, it's an exponential
decay curve. First, here's a practical solution:

Program used:

***********************************************
program Collisions;
uses
  SysUtils;
{$APPTYPE CONSOLE}
const
  KeyComb = 4294967296.0; //Ensure floating point constant.

var
  Product,Term:extended; // Maximum FPU precision possible.
  Iter,N:integer;

begin
  Product := 1;
  Write('How many keys? ');
  ReadLn(N);
  if N - 1 > 0 then
  begin
    for iter := 0 to N - 1 do
    begin
      Term := (KeyComb - 1) / KeyComb;
      Product := Product * Term;
    end;
  end;
  WriteLn('Probability of no collisions: ',Product);
end.
***********************************************

Results:

How many keys? 1
Probability of no collisions:  1
How many keys? 100
Probability of no collisions:  0.999999976716936
How many keys? 10000
Probability of no collisions:  0.999997671696274
How many keys? 1000000
Probability of no collisions:  0.999767196459270

Now what's the theoretical answer for your approximation for one million
keys? You can do this easily with a few logarithms:

it's Exp(ln(2^32 -1) - ln (2^32)) * 10^6)

= Exp ( -0.000000000233 * 10^6 ) = Exp( -0.000233 )

=  0.9997670271424

cf.0.999767196459270

So, our million multiplications agree to within one part in a million
with the logs. I'd call that a reasonable confidence.

[Don't you just love 80 bit floating point numbers? loadsa precision]

However, your approximation can be much improved on by calculating
things precisely, since it's very poor for large numbers of keys.

Statistical Model: 1 million keys of 32 bits with no collisions.

prob of no collision in first key is: P(0)= 1
prob of no collision in 2nd key, given no previous collisions is:

P(1) = (2^32 - 1) / (2^32)

Prob of 3rd key:

P(2) = (2^32 -2) / (2^32)

N+1 'th key:

P(N) = (2^32-N) / (2^32)

And you want to find:

Product (N:=0 to 10^6) { (2^32-N)/(2^32) }

Okay. One quick modification to the program. Change the line that read:

      Term := (KeyComb - 1) / KeyComb;

to say:

      Term := (KeyComb - N) / KeyComb;

And we get the following (very surprising) results:

How many keys? 10
Probability of no collisions:  0.999999976716936
How many keys? 1000
Probability of no collisions:  0.999767196432198
How many keys? 100000
Probability of no collisions:  0.0974580215385207
How many keys? 1000000
Probability of no collisions:  7.43297787552078 E-102

Yes... that is 0.0000 {102 zeros} 000743

It's actually fairly obvious why after about one hundred thousand keys
the probabilities become very small: when you add the one millionth key,
you have roughly a one in four thousand chance of duplicating by
mistake.

You don't have to multiply by 3999 / 4000 for very long to get a very
small answer, even after a few thousand multiplications by this factor,
the chances of no collisions become tiny.

Incidentally... just to remind you how darn fast modern processors are,
none of the calculations took more than a fraction of a second :-)

MH.

--
Martin Harvey.
mch24@harvey27.demon.co.uk
http://www.harvey27.demon.co.uk/mch24/
Technical Details
Message-ID: <37D577B0.B431C989@harvey27.demon.co.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.mbox.zip!not-for-mail
References: <7qtmmq$nia$1@lure.pipex.net> <37D54124.3FE11FD6@icb.co.at>

Show Full Headers
Complete Article Headers
Message-ID: <37D577B0.B431C989@harvey27.demon.co.uk>
Subject: Re: Uniqueness of Key ID
Date: Tue, 07 Sep 1999 00:00:00 +0000
From: Martin Harvey <mch24@harvey27.demon.co.uk>
References: <7qtmmq$nia$1@lure.pipex.net> <37D54124.3FE11FD6@icb.co.at>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.mbox.zip!not-for-mail
X-Deja-AN: 522264538
Content-Transfer-Encoding: 7bit
X-NNTP-Posting-Host: harvey27.demon.co.uk:158.152.222.177
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@demon.net
X-Trace: news.demon.co.uk 936738996 nnrp-01:28304 NO-IDENT harvey27.demon.co.uk:158.152.222.177
MIME-Version: 1.0
Newsgroups: alt.privacy,alt.privacy.anon-server,alt.security.pgp