Given a requirement for an N% sample, with order irrelevant, it's probably easiest to just do something like:
std::random_shuffle(randVals.begin(), randVals.end());
int num = randVals.size() * percent / 100.0;
auto pos = randVals.begin() + randVals.size() - num;
// get our sample
auto sample1{pos, randVals.end()};
// remove sample from original collection
randVals.erase(pos, randVals.end());
For some types of items in the array, you could improve this by moving items from the original array to the sample array, but for simple types like float
or double
, that won't accomplish anything.