How can i set my random function to only get me 2 results. I only want to get 2 questions per array not the 4 questions. random()
or arc4random()
? Not really sure which is better or what are the differences between this two methods! This is a different situation because Im using an struct for my array of Question.
struct Question {
var question: String!
var answers: [String]
var answer: Int!
var img: UIImage!
var info: String!
}
//Here is my viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
questions = [
Question(
question: "How old it was Steve Jobs in 2009?",
answers: ["10","30","19","20 "],
answer: 3,
img: UIImage.self(named: "steve"),
info: "Steve"
),]//....Here is more code with other questions
}
var questions = [Question]()//my array with the questions
var questionNumber = Int()
private func pickingRandomQuestion() {
let numberQuestion = questions.count
if numberQuestion > 0{
questionNumber = random() % questions.count//I only want to get 2 questions not the entire array of questions.
else {
NSLog("Done!")
}