title: Quiz app to pick questions from 8 group of questions randomly?
body: <p>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. </p>
  
  <ol>
  <li>8 questions from 1st group</li>
  <li>5 questions from 2nd group</li>
  <li>5 questions from 3rd group</li>
  <li>6 questions from 4th group</li>
  <li>6 questions from 5th group</li>
  <li>5 questions from 6th group</li>
  <li>9 questions from 7th group</li>
  <li>6 questions from 8th group</li>
  </ol>
  
  <p><strong>Total: 50 questions.</strong></p>
  
  <p>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.</p>
  
  <p><strong>Here is my code:</strong>
  (Because there are no comments on the code, ask me.)</p>
  
  <pre><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 &gt; 0 {
              QNumber = 0
              questionLabel.text = Questions[QNumber].Question
  
              answerNumber = Questions[QNumber].Answer
  
              for i in 0..&lt;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
          {
  
          }
      }
  }
  </code></pre>
  
  <p><strong>data.json</strong></p>
  
  <pre><code>[ {"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},]
  </code></pre>
  
  <p>This .json file is just an example there are more questions for every group. Every group has about 45 questions.</p>