Skip to content

Instantly share code, notes, and snippets.

View 10high's full-sized avatar

Michael Waaler 10high

  • 14:59 (UTC +02:00)
View GitHub Profile
@jlevy
jlevy / simple-hash.js
Last active July 7, 2025 14:18
Fast and simple insecure string hash for JavaScript
// These hashes are for algorithmic use cases, such as bucketing in hashtables, where security isn't
// needed and 32 or 64 bits is enough (that is, rare collisions are acceptable). These are way simpler
// than sha1 (and all its deps) or similar, and with a short, clean (base 36 alphanumeric) result.
// A simple, *insecure* 32-bit hash that's short, fast, and has no dependencies.
// Output is always 7 characters.
// Loosely based on the Java version; see
// https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript
const simpleHash = str => {
let hash = 0;