I'm doing a quiz game I need help. How can I make an array (called random questions) to exit and return to the same are not repeated.

You could shuffel your array before hand. Just take you array and randomly swap two elements for a while. So that the elements in the array are already in a random order to begin with. Then just take the first, second, third … until you reach the end of the array. In that way you wont get duplicats and dont have to remember which elements you already used.

example:

  • {1,2,3,4}
  • swap [2] and [0]
  • swap [3] and [2] … // as often as you want, with random indcies
  • {4,1,3,2} //result of swaping x times
  • return [0] → 4
  • return [1] → 1
  • return [2] → 3
  • return [3] → 2

completly random and without duplicats