Sampling a Random Line from a Text File

We have a new (free) tutorial in Towards Data Science/ about sampling algorithms for text files and other Rust iterators.

You might be put off because the article is framed as an technical interview question. However, even if you find this a bad interview question, we hope the article might still interest you as an algorithms tutorial.

The article ends with a new algorithm that reduces the number of calls made to the random number generator by half. Beyond the algorithms, the article covers practical issues including

  • Rust iterators that might contain error results
  • making random numbers deterministic
  • comparisons to Python

I love these algorithms and enjoyed working with them in Rust.