title: A quick string checksum function in Perl generating values in the 0..2^32-1 range
body: <p>I'm looking for a Perl string checksum function with the following properties:</p>
  
  <ul>
  <li>Input: Unicode string of undefined length (<code>$string</code>)</li>
  <li>Output: Unsigned integer (<code>$hash</code>), for which <code>0 &lt;= $hash &lt;= 2^32-1</code> holds (0 to 4294967295, matching the size of a 4-byte MySQL unsigned int)</li>
  </ul>
  
  <p>Pseudo-code:</p>
  
  <pre><code>sub checksum {
      my $string = shift;
      my $hash;
      ... checksum logic goes here ...
      die unless ($hash &gt;= 0);
      die unless ($hash &lt;= 4_294_967_295);
      return $hash;
  }
  </code></pre>
  
  <p>Ideally the checksum function should be quick to run and should generate values somewhat uniformly in the target space (<code>0</code> .. <code>2^32-1</code>) to avoid collisions. In this application random collisions are totally non-fatal, but obviously I want to avoid them to the extent that it is possible.</p>
  
  <p><b>Given these requirements, what is the best way to solve this?</b></p>