From 09672cda69a456ecc158af967d062183b74582df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Wed, 23 Nov 2022 04:36:40 +0100 Subject: [PATCH] class Random --- api/advent22_api/routers/_misc.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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(