fix: collision-free (seed,label) encoding in rollFor (review)

This commit is contained in:
2026-06-12 13:57:20 +00:00
parent 52d5008cdf
commit 3682205580
+3 -1
View File
@@ -24,5 +24,7 @@ export function makeRng(seed) {
// This is the whole hidden-variable mechanism: outcomes are fixed
// the moment their label exists, revealed whenever first asked for.
export function rollFor(seed, label) {
return makeRng(hash32(seed + ':' + label))();
// Length-prefix the seed so (seed, label) -> string is injective
// even though seeds and labels themselves contain ':'.
return makeRng(hash32(seed.length + ':' + seed + ':' + label))();
}