Reservoir Sampling is the answer to a common interview question.

import axle.stats._
import spire.math.Rational
import axle.math.arithmeticMean
import spire.implicits.DoubleAlgebra

Demonstrate it uniformly sampling 15 of the first 100 integers

val sample = reservoirSampleK(15, Stream.from(1)).drop(100).head
// sample: List[Int] = List(97, 91, 88, 76, 74, 66, 60, 57, 52, 46, 39, 26, 9, 5, 1)

val mean = arithmeticMean(sample.map(_.toDouble))
// mean: Double = 52.46666666666667

The mean of the sample should be in the ballpark of the mean of the entire list – 50.