(userId: string)
| 105 | // per-turn observer) with the same userId → cache the deterministic result. |
| 106 | let rollCache: { key: string; value: Roll } | undefined |
| 107 | export function roll(userId: string): Roll { |
| 108 | const key = userId + SALT |
| 109 | if (rollCache?.key === key) return rollCache.value |
| 110 | const value = rollFrom(mulberry32(hashString(key))) |
| 111 | rollCache = { key, value } |
| 112 | return value |
| 113 | } |
| 114 | |
| 115 | export function rollWithSeed(seed: string): Roll { |
| 116 | return rollFrom(mulberry32(hashString(seed))) |
no test coverage detected