I have a std::vector<int> for enabled cards.
I want the computer to choose one at random:
int r = 0;
r = rand() % m_enabledCards.size();
cardCount.push_back(m_enabledCards[r]);
For some reason this returns an index that is out of bounds and the vector has around 13 elements.
What could be wrong?
Thanks
Since I can’t see anything wrong with the code you posted, the error should be somewhere else, unless I overlooked something. Maybe your
m_enabledCardsvector is actually empty? Though that should give a “division by zero” error for the modulus line, I can’t think of any other reason with the given code.