
Show HN: TypeScript Implementation of Sequential Random Sampling - gliese1337
https://www.npmjs.com/package/vitter-sample
======
gliese1337
Inspired by the discussion on
[https://news.ycombinator.com/item?id=20960832](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.

