Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following simple script runs an infinite loop that fetches 2 random 20-byte sequences, calculates CRC16 and checks if there is a collision. Continuous evaluation of this loop de facto estimates collision percentage:</p> <pre><code>#!/usr/bin/env perl use Digest::CRC qw(crc16); open(my $f, '&lt;', '/dev/urandom'); my $n = 0; my $coll = 0; while (1) { read $f, $randstr1, 20; read $f, $randstr2, 20; my $crc1 = crc16($randstr1); my $crc2 = crc16($randstr2); $n++; $coll++ if $crc1 == $crc2; printf "percent of collisions = %.6f%%\n", $coll * 100.0 / $n if ($n % 100000 == 0); } </code></pre> <p>From what I get on my computer, collision percentage seems to be around <code>0.0016%</code> (or <code>1e-5</code>, or "1 in 100_000"), which is <em>way worse</em> than predicted estimates based on ideal hashing distribution of a 16-bit hash (such as 2^16 / 2^160).</p> <p><strong>UPDATE</strong>: I see you've clarified that 20 bytes are not just fully random bytes, but fall into range of <code>[a-z0-9]</code>. Here's the updated version that estimates collisions in that alphabet:</p> <pre><code>#!/usr/bin/env perl use Digest::CRC qw(crc16); my $n = 0; my $coll = 0; my @chars = ('a'..'z', '0'..'9'); sub randstr() { my $res; foreach (1..20) { $res .= $chars[rand @chars]; } return $res; } while (1) { my $crc1 = crc16(randstr()); my $crc2 = crc16(randstr()); $n++; $coll++ if $crc1 == $crc2; printf "percent of collisions = %.4f%%\n", $coll * 100.0 / $n if ($n % 100000 == 0); } </code></pre> <p>It yields approximately the same result, about <code>0.0016%</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload