public Question GetRandomQuestion() { Random random = new Random(); int randomNumber = 0; if (AvailableQuestionsByNumber.Count > 1) { List <int> listOfAvailableKeys = new List <int>(); foreach (var item in AvailableQuestionsByNumber) { listOfAvailableKeys.Add(item.Key); } int[] arrayOfAvailableKeys = listOfAvailableKeys.ToArray(); do { randomNumber = arrayOfAvailableKeys[random.Next(1, arrayOfAvailableKeys.Length)]; } while (AvailableQuestionsByNumber.Any(x => x.Key == randomNumber) == false); } else { randomNumber = AvailableQuestionsByNumber.Single().Key; } var question = AvailableQuestionsByNumber.Where(x => x.Key == randomNumber).Single(); return(question.Value); }
public void RemoveQuestionFromAvailableList(Question question) { var dictionaryQuestion = AvailableQuestionsByNumber.Where(x => x.Value == question).Single(); AvailableQuestionsByNumber.Remove(dictionaryQuestion.Key); }