title: Generate unique number based on string input in Javascript
body: <p>In the past I have made a function that generates an unique id (number) from a string. Today I discover that it is not as unique as should be. Never saw a problem before with it. Today two different inputs generates the same id (number).</p>
  
  <p>I use the same technique in Delphi, C++, PHP and Javascript to generate the same id's so there is no difference when different languages are involved to a project. For example this can be handy to communicate, for HTML id's, tempfiles etc.</p>
  
  <p>In general, what I do is calculate a CRC16 of a string, add the sum and return it.</p>
  
  <p>For example, these two strings generate the same id (number):</p>
  
  <pre><code>o.uniqueId( 'M:/Mijn Muziek/Various Artists/Revs &amp; ElBee - Tell It To My Heart.mp3' );
  o.uniqueId( 'M:/Mijn Muziek/Various Artists/Dwight Yoakam - The Back Of Your Hand.Mp3');
  </code></pre>
  
  <p>They both generates an id of 224904.</p>
  
  <p>The following example is a javascript example. My question is, how can i avoid (with a little change) that it generates a duplicate? (In case you might wonder what 'o.' means, it is the object where these functions belongs to):</p>
  
  <pre><code>o.getCrc16 = function(s, bSumPos) {
    if(typeof s !== 'string' || s.length === 0) {
      return 0;
    }
    var crc = 0xFFFF,
      L = s.length,
      sum = 0,
      x = 0,
      j = 0;
    for(var i = 0; i &lt; L; i++) {
      j = s.charCodeAt(i);
      sum += ((i + 1) * j);
      x = ((crc &gt;&gt; 8) ^ j) &amp; 0xFF;
      x ^= x &gt;&gt; 4;
      crc = ((crc &lt;&lt; 8) ^ (x &lt;&lt; 12) ^ (x &lt;&lt; 5) ^ x) &amp; 0xFFFF;
    }
    return crc + ((bSumPos ? 1 : 0) * sum);
  }
  o.uniqueId = function(s, bres) {
    if(s == undefined || typeof s != 'string') {
      if(!o.___uqidc) {
        o.___uqidc = 0;
      } else {
        ++o.___uqidc;
      }
      var od = new Date(),
        i = s = od.getTime() + '' + o.___uqidc;
    } else {
      var i = o.getCrc16(s, true);
    }
    return((bres) ? 'res:' : '') + (i + (i ? s.length : 0));
  };
  </code></pre>
  
  <p>How can I avoid duplicates with use of a little change to the code?</p>