mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-12-24 13:33:00 +00:00
class Random
This commit is contained in:
parent
de4881ced3
commit
09672cda69
1 changed files with 7 additions and 6 deletions
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue