public Question GetRandomQuestionAtLevel(int intLevel)
{
List<Question> lstQuestionPool = new List<Question>();
foreach (Question questionCurrent in lstQuestions)
{
if (questionCurrent.Level == intLevel)
{
lstQuestionPool.Add(questionCurrent);
}
}
if (lstQuestionPool.Count == 0) {
//MessageBox.Show("No Questions at level " + intLevel);
Console.WriteLine("No question at that level");
//return null;
return GetRandomQuestionAtLevel(intLevel - 1);
}
int randValue = Convert.ToInt32(rngPRNG.NextDouble() * (lstQuestionPool.Count - 0) + 0);
Question qSelected = null;
try
{
qSelected = lstQuestionPool[randValue];
}
catch (ArgumentOutOfRangeException)
{
qSelected = lstQuestionPool[randValue-1];
}
return qSelected;
}