I was playing around with the idea of a stream-based pseudo-random number generator in Scala using a linear congruential generator. The implementation obviously takes an LCG from the contant-time playing field to the linear-time field, however, I still think that it’s cool that it can be expressed so concisely with a stream. Here is what I came up with. If you try to calculate the stats, then you force the stream to evaluate to 10,000. Besides that, all calls to gen are like a regular LCG except that the results are backed by some sort of sequence in Scala.