import { localDateKey, normalizeTimezone } from '../../schedule-time.mjs'; export function hashString(input) { let hash = 2166136261; for (let i = 0; i < input.length; i += 1) { hash ^= input.charCodeAt(i); hash = Math.imul(hash, 16777619); } return Math.abs(hash); } /** 按用户 + 本地日期 + salt 从话术库稳定选取一条。 */ export function pickDailyLibraryEntry({ userId = '', timezone = 'Asia/Shanghai', now = Date.now(), library = [], salt = 'daily', } = {}) { const pool = Array.isArray(library) && library.length ? library : []; if (!pool.length) return ''; const tz = normalizeTimezone(timezone); const dateKey = localDateKey(now, tz); const seed = hashString(`${String(userId)}:${dateKey}:${salt}`); return pool[seed % pool.length]; }