Ha, those algorithms are far from trade secrets! Here's one of the Discover Weekly developers talking about how they implemented this feature:
https://atscaleconference.com/videos/creating-and-scaling-sp.... If you're interested, here's a deeper technical explanation of the algorithm used:
http://www.columbia.edu/~jwp2128/Teaching/W4721/papers/ieeec...