Skip to content

Commit b22b857

Browse files
baogorekclaude
authored andcommitted
Add optional salt parameter to seeded_rng
Supports per-subgroup RNG streams (e.g., congressional districts) while keeping the unsalted default distinct from any salted variant. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 895b429 commit b22b857

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

policyengine_us_data/utils/randomness.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def _stable_string_hash(s: str) -> np.uint64:
2323
return h
2424

2525

26-
def seeded_rng(variable_name: str) -> np.random.Generator:
26+
def seeded_rng(variable_name: str, salt: str = None) -> np.random.Generator:
2727
"""Create a per-variable RNG seeded by variable name hash."""
28-
seed = int(_stable_string_hash(variable_name)) % (2**63)
28+
key = variable_name if salt is None else f"{variable_name}:{salt}"
29+
seed = int(_stable_string_hash(key)) % (2**63)
2930
return np.random.default_rng(seed=seed)

0 commit comments

Comments
 (0)