I am working on an app that displays random trivia questions in the form of an array, but they tend to keep repeating. Is there a way to make them more random?
So, you do not want to show the same question repeatedly. Then something like this would be very near to what you want.
Code Block let array = [ "The first astronaut to step on the Moon was John Glenn", "The largest continent is Australia", "The Chicago Cubs won the World Series in 2015", "Delaware was the first state in the modern United States", "Alaska was the last state in the modern United States", //... ] var unusedQuestions: [String] = [] @IBAction func questButton(_ sender: Any) { if unusedQuestions.isEmpty { unusedQuestions = array.shuffled() } let nextQuestion = unusedQuestions.popLast()! questLabel.text = nextQuestion }