milia.core.seeds#

Deterministic seeds derived from arbitrary keys.

Python’s built-in hash() of a string changes between processes (it is salted by PYTHONHASHSEED), so seeding from it does not reproduce. seed() hashes the keys’ repr with BLAKE2 instead, which is stable everywhere.

Functions

rng(*keys)

A numpy generator seeded from seed().

seed(*keys)

A reproducible 32-bit seed from any sequence of keys.

milia.core.seeds.seed(*keys)#

A reproducible 32-bit seed from any sequence of keys.

Parameters:

*keys (object) – Values identifying the draw, e.g. an injection name, an entity and a day.

Return type:

int

Returns:

An integer in [0, 2**32), the same in every process.

Examples

>>> seed("stuck", 3, 7) == seed("stuck", 3, 7)
True
>>> seed("stuck", 3, 7) == seed("drift", 3, 7)
False
milia.core.seeds.rng(*keys)#

A numpy generator seeded from seed().

Parameters:

*keys (object) – Values identifying the draw.

Return type:

Generator

Returns:

A numpy.random.Generator.

Examples

>>> int(rng("a", 1).integers(100)) == int(rng("a", 1).integers(100))
True