docs(helpers): explain djb2 seed constant in stringHash

This commit is contained in:
kolaente 2026-04-05 14:12:53 +02:00 committed by kolaente
parent 65b6e55252
commit 4b3b5bb87c
1 changed files with 2 additions and 0 deletions

View File

@ -1,6 +1,8 @@
// Deterministic non-cryptographic string hash (djb2 variant).
// Used for stable pseudo-random selection keyed on date + user + bucket.
export function stringHash(input: string): number {
// 5381 is the canonical djb2 seed — a prime that empirically yields a good
// distribution when combined with the `hash * 33 + c` step below.
let hash = 5381
for (let i = 0; i < input.length; i++) {
// hash * 33 + char, kept in 32-bit range via `| 0`.