fix: collision-free (seed,label) encoding in rollFor (review)
This commit is contained in:
+3
-1
@@ -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))();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user