I am trying to make a riddle game in python but the problem is random function is repeating questions. I want that questions do not repeat can someone please help
Asked
Active
Viewed 31 times
-1
-
please share the code section where you are randomising! – anurag Jan 07 '21 at 16:12
-
3Put the questions in a list. Shuffle the list. Process the shuffled list in order. – Barmar Jan 07 '21 at 16:13
-
@Barmar, it still _can_ repeat the questions! – anurag Jan 07 '21 at 16:15
-
2@anurag Only if there are duplicates in the original list or you go back to the beginning for some reason. – Barmar Jan 07 '21 at 16:19
1 Answers
0
Place all the questions in the list and use this function
import random
random_indexes=random.sample(range(len(lst), no_of_questions))
Then iterate over the random_indexes and get the questions.

Maleehak
- 671
- 8
- 17