mash.js 544 B

1234567891011121314151617181920212223
  1. // From http://baagoe.com/en/RandomMusings/javascript/
  2. // Johannes Baagøe <baagoe@baagoe.com>, 2010
  3. function Mash() {
  4. var n = 0xefc8249d;
  5. var mash = function(data) {
  6. data = data.toString();
  7. for (var i = 0; i < data.length; i++) {
  8. n += data.charCodeAt(i);
  9. var h = 0.02519603282416938 * n;
  10. n = h >>> 0;
  11. h -= n;
  12. h *= n;
  13. n = h >>> 0;
  14. h -= n;
  15. n += h * 0x100000000; // 2^32
  16. }
  17. return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
  18. };
  19. mash.version = 'Mash 0.9';
  20. return mash;
  21. }