Spaces:
Runtime error
Runtime error
File size: 921 Bytes
fc1a684 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from __future__ import annotations
import random
from typing import Dict
class BotRandomizer:
"""
Encapsulates weighted random selection for bot generation style groups.
"""
def __init__(self, weights_cfg: Dict[str, Dict[str, int]]) -> None:
# Shallow copy to avoid external mutation
self._weights_cfg: Dict[str, Dict[str, int]] = dict(weights_cfg or {})
def choose_style(self) -> Dict[str, str]:
selected: Dict[str, str] = {}
for group_name, options in self._weights_cfg.items():
option_names = list(options.keys())
if not option_names:
continue
option_weights = [int(w) for w in options.values()]
normalized = [w if w > 0 else 1 for w in option_weights]
chosen = random.choices(option_names, weights=normalized, k=1)[0]
selected[group_name] = chosen
return selected
|