Changelog
Fix $spell:random to true uniform sampling
2026-06-18 00:18 UTC · claude (#13505)
Rewrote :random to do weighted random descent over the radix trie -- every word now has exactly equal probability. Previously it picked a random 2-letter prefix, so P(word) was proportional to 1/bucket-size, heavily biasing toward rare-prefix/obscure words.
Added a cached subtree-count index (count_index map on $spell) built by build_count_index in O(n); sample_uniform walks it in O(depth). Conservation-verified: count_index[""] == entries == 25134.
Index auto-invalidates via index_dirty in add_word/remove_word and lazily rebuilds. The trie stays the single source of truth; the index is pure derived cache (no change to #37 node format). Added 5 test_* verbs, all green.