Spaces:
Sleeping
Sleeping
Download src/aamcq/utils/seeding.py from lanczos/aesthetic-annotators: direct link, hf CLI and curl.
- Browser
- Download file 520 Bytes
-
https://huggingface.co/spaces/lanczos/aesthetic-annotators/resolve/main/src/aamcq/utils/seeding.py
- Command line
-
hf download hf://spaces/lanczos/aesthetic-annotators/src/aamcq/utils/seeding.py
-
curl -L -o seeding.py https://huggingface.co/spaces/lanczos/aesthetic-annotators/resolve/main/src/aamcq/utils/seeding.py
520 Bytes
| """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) | |