import type { Rng } from "./types"; export const clamp = (n: number, lo = 0, hi = 100): number => Math.max(lo, Math.min(hi, n)); export const clamp01 = (n: number): number => Math.max(0, Math.min(1, n)); export const pick = (a: readonly T[], rng: Rng = Math.random): T => a[Math.floor(rng() * a.length)]; export const hhmm = (d: Date = new Date()): string => d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hour12: false }); export function shuffle(a: T[], rng: Rng = Math.random): T[] { for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(rng() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; }