dimanche 11 septembre 2016

How only get 2 questions from an array with 4 questions! Swift

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!

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!")
}




Aucun commentaire:

Enregistrer un commentaire