JSFiddle - React, Tailwind, and code Playground
by Dogbert
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.1/vue.min.js"></script>
<div id="app">
<p>
Number of items <input v-model="count">
</p>
<p>
Hash size (bits) <input v-model="bits">
</p>
<p>
Expected number of collisions: {{collisions}}
</p>
</div>
JavaScript
new Vue({
el: '#app',
data: {
count: 1e6,
bits: 64,
},
computed: {
collisions: function() {
var n = this.count, d = Math.pow(2, this.bits);
console.log(n, d);
return n - d + d * Math.pow((d - 1) / d, n);
}
}
});