cutcutcodec.core.interfaces.seedable.Seedable

class cutcutcodec.core.interfaces.seedable.Seedable(seed: Real | None = None)[source]

Interface for appening a seed management.

Attributes

seedfloat

The value of the seed between [0, 1[ (readonly).

seed_bytesbytes

The hashed version of the seed. Contains 32 bytes, ie 256 bits.

Initialise and create the class.

Parameters

seednumbers.Real, optional

The random seed to have a repeatability. The value must be between 0 included and 1 excluded. If not provided, the seed is chosen randomly.

property seed: float

Return the value of the seed between 0 and 1.

Examples

>>> from fractions import Fraction
>>> from cutcutcodec.core.interfaces.seedable import Seedable
>>> Seedable(0).seed  # int
0.0
>>> Seedable(Fraction(1, 2)).seed  # fraction
0.5
>>> Seedable(0.5).seed  # float
0.5
>>>
property seed_bytes: bytes

Return the bytes seed string, containing 256 bits.

Examples

>>> from cutcutcodec.core.interfaces.seedable import Seedable
>>> Seedable(0.25).seed_bytes
b"'/x\x03m\xb6r\x1f|\xf7DC\x15\xe5\xf66\x04&\xd1L=Dmj\xe8\xa8\x9e\xf7\r\x13@\x02"
>>>