I built a small Christmas toy this month: an elf name generator where you type your first name and birth month and get a two-part elf name like "Jingle Sparkletoes", plus a workshop job.

The one product rule I cared about: the same two answers must always give the same name. People share their elf name in a group chat, a friend types the same thing, and if the friend gets a different result the whole joke falls apart. So no Math.random().

Hash the input, index into word lists

The generator keeps three plain arrays: first parts, second parts and job titles. The input is normalised into a key, and a 32-bit FNV-1a style hash picks an index into each list:

function hash(str) { var h = 0x811c9dc5; for (var i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = (h + ((h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24))) >>> 0; } return h >>> 0; } function buildXmas(name, month) { var clean = name.trim().replace(/\s+/g, ' '); var key = clean.toLowerCase() + '|' + month.toLowerCase(); var fi = hash(key) % FIRST.length; var si = hash(key + '~second') % SECOND.length; var ti = hash(key + '~title') % TITLES.length; return { name: FIRST[fi] + ' ' + SECOND[si], job: TITLES[ti] }; } 

A few details that turned out to matter:

  • Normalise before hashing. "Emma ", "emma" and "EMMA" should be the same person, so the key is trimmed, collapsed and lower-cased.
  • Salt each pick separately. Hashing key, key + '~second' and key + '~title' gives three roughly independent picks from one input. Using one hash with different moduli makes the parts correlate when the list lengths share factors.
  • >>> 0 everywhere. JavaScript bitwise operators work on signed 32-bit ints, so without the unsigned shift you get negative numbers and negative array indexes.
  • Let the month shift the result. The real version also adds the month index to the first and second picks, so siblings with the same name but different birthdays don't collide.

Why not a seeded PRNG?

A seeded PRNG would work too, but you would still need to hash the string into a seed first. For three picks the hash on its own is shorter and easier to reason about. Nothing here is security-sensitive, so a fast non-cryptographic hash is fine.

The result

It runs entirely in the browser with no backend: My Elf Name. There is also a fantasy mode that picks names by gender and style for D&D characters, and a card you can print or send as a link.

If you've built something "random but repeatable" like this, I'd like to know which hash you used.