class Random

This commit is contained in:
Jörn-Michael Miehe 2022-11-23 04:36:40 +01:00
parent de4881ced3
commit 09672cda69

View file

@ -15,9 +15,11 @@ from ._image import AdventImage
########## ##########
async def get_rnd(bonus_salt: Any = "") -> random.Random: class Random(random.Random):
cfg = await get_config() @classmethod
return random.Random(f"{cfg.puzzle.solution}{bonus_salt}") 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: 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: async def shuffle(seq: Sequence, rnd: random.Random | None = None) -> list:
# Zufallsgenerator # Zufallsgenerator
if rnd is None: rnd = rnd or await Random.get()
rnd = await get_rnd()
# Elemente mischen # Elemente mischen
return rnd.sample(seq, len(seq)) return rnd.sample(seq, len(seq))
@ -89,7 +90,7 @@ async def get_auto_image(
# hier niemals RuntimeError! # hier niemals RuntimeError!
image = await load_image(images[index]) image = await load_image(images[index])
rnd = await get_rnd(index) rnd = await Random.get(index)
# Buchstabe verstecken # Buchstabe verstecken
await image.hide_text( await image.hide_text(