mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 08:13:01 +00:00
20 lines
511 B
Python
20 lines
511 B
Python
import itertools
|
|
import random
|
|
from typing import Sequence
|
|
|
|
from ..dav_common import dav_get_file
|
|
|
|
|
|
async def get_loesungswort() -> str:
|
|
fp = await dav_get_file("loesungswort.txt")
|
|
return fp.read().decode("utf8").strip()
|
|
|
|
|
|
async def shuffle(seq: Sequence, length: int | None = None) -> list:
|
|
rnd = random.Random(await get_loesungswort())
|
|
|
|
if length is not None:
|
|
infinity = itertools.cycle(seq)
|
|
seq = list(itertools.islice(infinity, length))
|
|
|
|
return rnd.sample(seq, len(seq))
|