0

I need to make random choices from the questions in my quiz app, but this code I've written repeats numbers. How can I prevent the repeats?

var correctans = num1.text!.toInt()! + num2.text!.toInt()!
    var randomans1 = (arc4random()%8) + 1
    var randomans2 = (arc4random()%7) + 1
    var randomans3 = (arc4random()%6) + 1
    var randomans4 = (arc4random()%5) + 1


    switch (randomplace) {

        case 1:

            btn3.setTitle("\(correctans)", forState: UIControlState.Normal)
            btn4.setTitle("\(randomans1)", forState: UIControlState.Normal)
            btn2.setTitle("\(randomans3)", forState: UIControlState.Normal)
            btn1.setTitle("\(randomans4)", forState: UIControlState.Normal)

            break
jscs
  • 63,694
  • 13
  • 151
  • 195

0 Answers0