"""
STARWASTE - Shared Utilities
Common utility functions
"""

import random
import hashlib
from typing import Tuple
from rich.console import Console

# Global console for consistent output across all modules
# Automatically handles emoji fallbacks on Windows
console = Console()


def seed_from_string(seed_str: str) -> int:
    """Convert string seed to integer"""
    return int(hashlib.md5(seed_str.encode()).hexdigest(), 16) % (2**31)


def distance(x1: float, y1: float, x2: float, y2: float) -> float:
    """Calculate distance between two points"""
    return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5


class SeededRandom:
    """Seeded random number generator"""
    
    def __init__(self, seed: int):
        self.rng = random.Random(seed)
    
    def randint(self, a: int, b: int) -> int:
        return self.rng.randint(a, b)
    
    def random(self) -> float:
        return self.rng.random()
    
    def choice(self, seq):
        return self.rng.choice(seq)
