diff --git a/api/advent22_api/routers/_misc.py b/api/advent22_api/routers/_misc.py index 68a929e..3e099ae 100644 --- a/api/advent22_api/routers/_misc.py +++ b/api/advent22_api/routers/_misc.py @@ -15,9 +15,11 @@ from ._image import AdventImage ########## -async def get_rnd(bonus_salt: Any = "") -> random.Random: - cfg = await get_config() - return random.Random(f"{cfg.puzzle.solution}{bonus_salt}") +class Random(random.Random): + @classmethod + async def get(cls, bonus_salt: Any = "") -> "Random": + cfg = await get_config() + return cls(f"{cfg.puzzle.solution}{bonus_salt}") async def set_length(seq: Sequence, length: int) -> list: @@ -29,8 +31,7 @@ async def set_length(seq: Sequence, length: int) -> list: async def shuffle(seq: Sequence, rnd: random.Random | None = None) -> list: # Zufallsgenerator - if rnd is None: - rnd = await get_rnd() + rnd = rnd or await Random.get() # Elemente mischen return rnd.sample(seq, len(seq)) @@ -89,7 +90,7 @@ async def get_auto_image( # hier niemals RuntimeError! image = await load_image(images[index]) - rnd = await get_rnd(index) + rnd = await Random.get(index) # Buchstabe verstecken await image.hide_text(