Post

✨ It's new samwho visual essay o'clock! ✨ Reservoir sampling is one of my favourite algorithms. It allows you to sample from a set without knowing the size of that set. I try to assume no prior knowledge, and use no scary math notation. Just beautiful visuals. Let me know what you think! ❤️

35 reposts224 likes

thank you for your really great article. funnily I needed exactly this 2 weeks ago when I did a toy-implementation of monte-carlo game trees (which is still not working, but one of my errors was selecting always 50%). I'm looking forward to more articles like this :)

Amazing article! The logs are hilarious. Turtle rejecting a PR due to "bad vibes" is one of my favs. Also 👏👏👏 for shipping readable javascript that I can inspect in the browser.

Easy follow and subscribe. This is exactly the kind of content we need in the dev world. All too often someone doesn't know how to ELI5 because they don't really understand the concept or because they want to gatekeep to sell more content. Truly open source learning. Thank you!

Thank you so much, Greg 😁 I went into this one expecting it to be easy. I knew the algorithm well, it’s easy to implement, and the math behind it isn’t exotic. I was super wrong. Reworked it twice, almost in full both times. Struggled tremendously to explain the math in a way that felt intuitive.

It’s been posted to the orange site. If you read it and enjoyed it, I’d be super grateful for an upvote over there. 🙏❤️

Not even finished yet, but "For example, let's say you're building a log collection service. Text logs, not wooden ones." had me rolling. I'm having too much fun shuffling cards, though. Might never finish at this rate 😅

One potential fix would be to calculate `j` as `floor(random()*(this.n+1))`. Also, in the multi-card example, it wasn't obvious that "generate a random number between 0 and *n*" assumes that *n* is not included. This is also confusing because, up to that point in the article, we counted *n* from 1.

Great write up! These visuals would have saved me quite a bit of time back when I was still a junior engineer and came across reservoir sampling for the first time 🤣