Use an iterator instead of an array in sampleMany.

It saves a lot of memory when sampling a lot of data.