If a function is specified random_num_in_range(more on this later), you should not roll your own sampler so hard:
template<typename It, typename OutIt>
void sample(It b, It e, OutIt o, size_t n)
{
const size_t s = std::distance(b, e);
for(size_t i = 0; i < n; ++i)
{
It it = b;
std::advance(it, random_num_in_range(s));
*(o++) = *it;
}
}
You could use it, perhaps like this:
vector<int> input;
...
vector<int> output;
sample(input.begin(), input.end(), back_inserter(output), 100);
, random_number_in_range . , ( , , - - ).