List pickUpRandomQuestion()

in frontend/frontend-flutter/lib/services/new_suggestions/new_suggestion_cubit.dart [296:334]


  List<String> pickUpRandomQuestion(
      String question, List<String> questionList) {
    List<String> list = [];
    int lengthScenario = 0;
    Random random = new Random();
    List<String> listQuestionsScenario = [];
    int randomNumber = 0;
    String candidateQuestion = "";
    Map<String, String> map = {};

    print('NewSuggestionCubit: pickUpRandomQuestion() : START');
    print('NewSuggestionCubit: pickUpRandomQuestion() : question = $question');

    for (int i = 0; list.length <= 3; i++) {
      randomNumber = random.nextInt(questionList.length);
      candidateQuestion = questionList[randomNumber];
      print(
          'NewSuggestionCubit: pickUpRandomQuestion() : candidateQuestion = $candidateQuestion');
      if (question != candidateQuestion) {
        print(
            'NewSuggestionCubit: pickUpRandomQuestion() : if(question != candidateQuestion) : candidateQuestion = $candidateQuestion');
        if (!map.containsKey(candidateQuestion)) {
          print(
              'NewSuggestionCubit: pickUpRandomQuestion() : !map.containsKey(candidateQuestion : adding candidateQuestion');
          map[candidateQuestion] = candidateQuestion;
          list.add(candidateQuestion);
        }
      }
      //listQuestionsScenario may contain less than 3 questions (including the asked question
      //so we check that and break the loop if we retreived all the candidate questions
      if (list.length == questionList.length - 1) {
        break;
      }
    }

    print('NewSuggestionCubit: pickUpRandomQuestion() : list = $list');

    return list;
  }