I have this code:
int generatore(std::vector<bool> vettore, int *x) {
int y;
if (std::adjacent_find(vettore.begin(), vettore.end(), std::not_equal_to<>()) == vettore.end) {
return *x + 1;
}
else {
do {
y = rand() % *x;
} while (vettore.at(y) == true);
return y;
}
}
What this function does is basically get a vector that stores boolean values that say if the indexes have already been used and its size, when it is called it should return an index from the ones that hadn't been used or *x+1 if all of them had been. The vector used as parameter will never be empty. A false value would mean that that index hasn't been used, the problem with this code is that if all of the values are equal to false it returns *x+1 instead of choosing one random index, so i should only check if all the values are equal to true, what should i change?
Aucun commentaire:
Enregistrer un commentaire