1 comment

[ 3.8 ms ] story [ 17.1 ms ] thread
Inspired by the discussion on https://news.ycombinator.com/item?id=20960832, and the author of that article's complaint that there wasn't any source code online, I went ahead and ported the algorithm to TypeScript/JavaScript. As it happens, Vitter's sequential random sampling actually solves a rather annoying problem I had at work recently, so this was a practical as well as theoretical / for-fun exercise.

Numerical code like this is also a prime candidate for implementation via WebAssembly, but while I've been able to produce a working transformed version of the code which acts like a restartable co-routine (i.e., manually, without relying on language-supported generators), getting the compiled WASM to actually run correctly in a JS environment has not worked out so far. I expect that will be version 2.0.0.