Latest recipes tagged "collision"http://code.activestate.com/recipes/tags/collision/new/2012-12-21T09:32:54-08:00ActiveState Code RecipesHash collision probability / Birthday problem (Python) 2012-12-21T09:32:54-08:00Sander Evershttp://code.activestate.com/recipes/users/4173111/http://code.activestate.com/recipes/578387-hash-collision-probability-birthday-problem/ <p style="color: grey"> Python recipe 578387 by <a href="/recipes/users/4173111/">Sander Evers</a> (<a href="/recipes/tags/birthday/">birthday</a>, <a href="/recipes/tags/collision/">collision</a>, <a href="/recipes/tags/hash/">hash</a>). </p> <p>Calculates the probability that, when making <em>k</em> random selections out of <em>n</em> possibilities, at least two of the selections are the same. See: <a href="http://en.wikipedia.org/wiki/Birthday_problem" rel="nofollow">http://en.wikipedia.org/wiki/Birthday_problem</a></p> <p>What is the probability that (at least) two people in a class of 30 share their birthday?</p> <pre class="prettyprint"><code>&gt;&gt;&gt; collide(30,365) 0.7063162427192688 </code></pre> <p>What is the probability that ORA_HASH generates the same hash when hashing 25000 values?</p> <pre class="prettyprint"><code>&gt;&gt;&gt; collide(25000,int(4.3e9)) 0.07009388771353198 </code></pre>