Use an iterator instead of a array in sampleMany

It saves a lot of memory when sampling a lot of data.

Asking a review from @jubianchi and other @hoaproject/hoackers.