staging-org / ocean-landing-serve / src/ lib/ sample-hash.ts

// Deterministic stand-ins for hashes and versions in sample data, so every render shows the same values.
export const seed = (s: string) => [...s].reduce((h, ch) => (Math.imul(h, 31) + ch.charCodeAt(0)) >>> 0, 7);

export const hex = (s: string, n: number) => {
	let h = seed(s);
	let out = '';
	while (out.length < n) {
		h = (Math.imul(h, 1_103_515_245) + 12_345) >>> 0;
		out += h.toString(16).padStart(8, '0');
	}
	return out.slice(0, n);
};