如何设置我的随机功能只能得到2个结果。我只希望每个阵列得到2个问题而不是4个问题。 random()
或arc4random()
?不确定哪个更好或这两种方法有什么区别!这是一种不同的情况,因为我在我的问题数组中使用了一个结构。
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!")
}