Hi;
I have a Q/A based game which randomly selects questions that are stored in access file table. I have define a vector and a stdstream that takes no of questions as input. The no of records are 300 and I want the program to select only 30 questions but they should be slected randomly from 300, but my problem is it just selects the first 30 records when user chooses no of quetion to be 30. If user chooses no of questions to be 100 or 300 then it takes into account 100 or 300 records. How can I manage this. Below are functions that are used.
std::vector<bool> m_Qtable; // vector defination
std::stringstream sa; //string stream
sa << p.question; //input
sa >> m_QNo; //output
m_Qtable.clear();
m_Qtable.resize(m_QNo);
qnum = GetNextQuestion();
m_db.m_ID = qnum; //record ID is taken as question num
Function for Getnext question which is randomly selectd from m_QNo.
int CGME::GetNextQuestion()
{
int i;
i = rand() % m_QNo;
while(m_Qtable[i])
i =rand() % m_m_QNo;
m_Qtable[i] = true;
return i+1;
}
I'll be waiting for your feedback. If above code is not much for understanding the problem , I can provide further information.
Regards