Centralize helper seed selection

This commit is contained in:
2026-06-27 14:16:03 +02:00
parent c7e4bdc373
commit 7bc08ada47
4 changed files with 57 additions and 39 deletions
+22 -1
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
import json
import random
from typing import Any
from typing import Any, Iterable
SEED_AXIS_SALTS = {
@@ -189,6 +189,27 @@ def configured_axis_seed(seed_config: dict[str, int], axis: str) -> int | None:
return None
def configured_seed_from_axes(
seed_config: str | dict[str, Any] | None,
axes: Iterable[str],
*,
extra_keys: Iterable[str] = (),
) -> int | None:
try:
parsed = parse_seed_config(seed_config)
except ValueError:
return None
for axis in axes:
value = configured_axis_seed(parsed, axis)
if value is not None:
return value
for key in extra_keys:
value = parsed.get(str(key))
if value is not None and value >= 0:
return value
return None
def axis_rng(seed_config: dict[str, int], axis: str, base_seed: int, row_number: int) -> random.Random:
configured = configured_axis_seed(seed_config, axis)
salt = SEED_AXIS_SALTS.get(axis, 0)