Quiz app to pick questions from 8 group of questions randomly? swift - json : I build an application for iOS and i want it to pick questions from 8 different groups of questions and randomly. The number of questions is 356 and only 50 of them must be picked randomly. 

 1. 8 questions from 1st group
 2. 5 questions from 2nd group
 3. 5 questions from 3rd group
 4. 6 questions from 4th group
 5. 6 questions from 5th group
 6. 5 questions from 6th group
 7. 9 questions from 7th group
 8. 6 questions from 8th group

**Total: 50 questions.**

What i did is that, i build the quiz, but it reads all the questions and shows them to the user. The questions are read from a .json file.

**Here is my code:** 

    import UIKit
    
    struct Question {
        var Question: String!
        var Answers: [String]!
        var Answer: Int!
        
        init(item: [String: Any])
        {
            self.Question = item["Question"] as? String
            self.Answers = item["Answers"] as? [String]
            self.Answer = item["Answer"] as? Int
        }
    } 
    
    class LittleTestViewController: UIViewController {
        
        //MARK: Properties
        @IBOutlet weak var questionLabel: UILabel!
        @IBOutlet var buttons: [UIButton]!
    
        var Questions = [Question]()
        var QNumber = Int()
        var answerNumber = Int()
    
    override func viewDidLoad() {
            super.viewDidLoad()
    
            jsonParsingQuestionsFile()
            pickQuestion()
        }
    
        func jsonParsingQuestionsFile ()
        {
            guard let path = Bundle.main.path(forResource: "data", ofType: "json"),
                let array = (try? JSONSerialization.jsonObject(with: Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe), options: JSONSerialization.ReadingOptions.allowFragments)) as? [[String : Any]] else{
                    return
            }
            for item in array
            {
                self.Questions.append(Question(item: item))
            }
        }
        
        func pickQuestion ()
        {
            if Questions.count > 0 {
                QNumber = 0
                questionLabel.text = Questions[QNumber].Question
                
                answerNumber = Questions[QNumber].Answer
                
                for i in 0..<buttons.count{
                    buttons[i].setTitle(Questions[QNumber].Answers[i], for: UIControlState.normal)
                }
                Questions.remove(at: QNumber)
            }
            else
            {
               print ("End")
            }
        }
    
    @IBAction func btn1(_ sender: UIButton){
            Unhide()
            if answerNumber == 0 {
                print ("Correct!!")
            }
            else
            {
                
            }
        }
        
        @IBAction func btn2(_ sender: UIButton) {
            Unhide()
            if answerNumber == 1 {
               print ("Correct!!")
            }
            else
            {
    
            }
        }
        @IBAction func btn3(_ sender: UIButton) {
            Unhide()
            if answerNumber == 2 {
                print ("Correct!!")
            }
            else
            {
                
            }
        }
        @IBAction func btn4(_ sender: UIButton) {
            Unhide()
            if answerNumber == 3 {
                print ("Correct!!")
            }
            else
            {
                
            }
        }
    }

**data.json**

 

    [ {"Question":"Group 1. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 1. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 1. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 3},
      {"Question":"Group 2. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 2. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 1},
      {"Question":"Group 2. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 3. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 3. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 4. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 4. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 3},
      {"Question":"Group 4. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 5. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 0},
      {"Question":"Group 5. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 6. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 0},
      {"Question":"Group 7. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},
      {"Question":"Group 8. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 0},
      {"Question":"Group 8. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 1},
      {"Question":"Group 9. lalala?", "Answers":["lala","trtr","asas","bbbb"],"Answer": 2},]



> This .json file is just an example there are more questions for every
> group. Every group has about 45 questions.

