sansreplace: a novel O(k log k) sampling-without-replacement algorithm with zero extra memory

burny_tech · x · 2026-10-13

Developer ciphergoth has open-sourced sansreplace, featuring "Cardchoose," an algorithm he says he found eight years ago and believes is still novel: fairly sample k distinct integers below n using only the output vector — no hash set, no extra memory, O(k log k).

The innovation is a step that deliberately favors duplicates, then removes them via a sort-plus-offset mapping, eliminating auxiliary data structures. The repo ships Python, C++, and Rust implementations, algorithm write-ups, prior-art notes, and benchmark results, under Apache-2.0.

Original post →

More from Research

Research channel →