This commit is contained in:
Jörn-Michael Miehe 2022-10-14 23:20:35 +00:00
parent 12ed54f925
commit 3bee806262

View file

@ -12,10 +12,15 @@ async def get_loesungswort() -> str:
async def set_length(seq: Sequence, length: int) -> list: async def set_length(seq: Sequence, length: int) -> list:
# `seq` unendlich wiederholen
infinite = itertools.cycle(seq) infinite = itertools.cycle(seq)
# Die ersten `length` einträge nehmen
return list(itertools.islice(infinite, length)) return list(itertools.islice(infinite, length))
async def shuffle(seq: Sequence) -> list: async def shuffle(seq: Sequence) -> list:
# Zufallsgenerator
rnd = random.Random(await get_loesungswort()) rnd = random.Random(await get_loesungswort())
# Elemente mischen
return rnd.sample(seq, len(seq)) return rnd.sample(seq, len(seq))