/
Mihaham
/
Table-Time
Обзор
Документация
Войти
/
Mihaham
/
Table-Time
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
services/api/app/plugins/shared/dice.py
24 строки
821 B
MihahamYT
feat: dedicated web panels for all 46 games
14 июн 2026, 21:36
14 июн 2026, 21:36
4e11c3f
Код
Авторство
О чём код?
"""Dice rolling and face counting utilities.""" import random import secrets from collections.abc import Callable def roll_dice(count: int, sides: int = 6, rng: Callable[[], int] | None = None) -> list[int]: """Roll `count` dice with `sides` faces each.""" if count <= 0: return [] roll = rng if rng is not None else (lambda: secrets.randbelow(sides) + 1) return [roll() for _ in range(count)] def roll_dice_seeded(count: int, sides: int = 6, seed: int | None = None) -> list[int]: """Deterministic dice roll for tests.""" rng = random.Random(seed if seed is not None else 0) return [rng.randint(1, sides) for _ in range(count)] def count_face(dice: list[int], face: int) -> int: """Count occurrences of a face value in dice.""" return sum(1 for d in dice if d == face)