2022-10-14 22:47:16 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-14 23:03:36 +00:00
|
|
|
async def set_length(seq: Sequence, length: int) -> list:
|
|
|
|
infinite = itertools.cycle(seq)
|
|
|
|
return list(itertools.islice(infinite, length))
|
|
|
|
|
2022-10-14 22:47:16 +00:00
|
|
|
|
2022-10-14 23:03:36 +00:00
|
|
|
async def shuffle(seq: Sequence) -> list:
|
|
|
|
rnd = random.Random(await get_loesungswort())
|
2022-10-14 22:47:16 +00:00
|
|
|
return rnd.sample(seq, len(seq))
|