Spaces:
Sleeping
Sleeping
File size: 520 Bytes
871ff87 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | """Deterministic seed derivation."""
from __future__ import annotations
import hashlib
def item_seed(item_id: str, master_seed: int = 0, purpose: str = "") -> int:
"""Derive a 32-bit seed from (item_id, master_seed, purpose).
Stable across runs and across machines — we rely on SHA-256, not Python's
string hash randomization.
"""
blob = f"{master_seed}|{item_id}|{purpose}".encode("utf-8")
digest = hashlib.sha256(blob).digest()
return int.from_bytes(digest[:4], "big", signed=False)
|