Write reservoirSample(stream, k, rng). stream is any iterable that can be read once (it may be a generator), and its length is unknown. Return an array of k items so that every k-subset of the stream is equally likely.
rng returns numbers in [0, 1)- The first
k items go straight into the reservoir, with no draw - For the i-th item (counting from 1) with
i > k, draw once and set slot = Math.floor(rng() * i). If slot < k, the item replaces reservoir[slot] - If the stream has fewer than
k items, return all of them in arrival order; k = 0 gives [] - Use O(k) memory: never store the whole stream