mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 16:23:00 +00:00
26 lines
679 B
Python
26 lines
679 B
Python
import itertools
|
|
import random
|
|
from typing import Any, Sequence
|
|
|
|
from ..config import get_config
|
|
|
|
|
|
async def get_rnd(bonus_salt: Any = "") -> random.Random:
|
|
cfg = await get_config()
|
|
return random.Random(f"{cfg.solution}{bonus_salt}")
|
|
|
|
|
|
async def set_length(seq: Sequence, length: int) -> list:
|
|
# `seq` unendlich wiederholen
|
|
infinite = itertools.cycle(seq)
|
|
# Die ersten `length` einträge nehmen
|
|
return list(itertools.islice(infinite, length))
|
|
|
|
|
|
async def shuffle(seq: Sequence, rnd: random.Random | None = None) -> list:
|
|
# Zufallsgenerator
|
|
if rnd is None:
|
|
rnd = await get_rnd()
|
|
|
|
# Elemente mischen
|
|
return rnd.sample(seq, len(seq))
|