I created a simple random number generator on Angela Yu's dicee app section. I used a print statement and and the code was generating random numbers. I side loaded the app onto my iphone 10 and the app would not make the dice change. This has happened a c

import UIKit


class ViewController: UIViewController {

var randomDiceIndex1 : Int = 0

var randomDiceIndex2 : Int = 0


@IBOutlet weak var diceImageView1: UIImageView!

@IBOutlet weak var diceimageView2: UIImageView!

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

}


@IBAction func rollButtonPressed(_ sender: UIButton) {

randomDiceIndex1 = Int.random(in:0...6)

randomDiceIndex2 = Int.random(in:0...6

)


}

}

Replies

I suppose you are new to the forum. Welcome, but a few important advices to start.


Don't put the whole question in the title. It is properly impossible to read. In addition, the question is truncated, so we don't understand what you are asking.

=> Use the action menu to give a short title, and detail the question in the post itself.


Question: where in this code do you expect to see the dice change ? Where do you set diceImageView1 or diceImageView2 ?

Where do you see it change (in simulator I guess) ?

Where is the print statement you mention in the title ?

Note that this print will not show once app is downloaded and not launched from XCode but from the device. You should instead update the diceImageView1 and diceImageView2 with the appropriate image of dice face.


Please, also use code formatter (<>) to format your code as follows (remove empty lines as well):


import UIKit

class ViewController: UIViewController {
  
    var randomDiceIndex1 : Int = 0
    var randomDiceIndex2 : Int = 0
  
    @IBOutlet weak var diceImageView1: UIImageView!
  
    @IBOutlet weak var diceimageView2: UIImageView!
  
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func rollButtonPressed(_ sender: UIButton) {
        randomDiceIndex1 = Int.random(in:0...6)
      
        randomDiceIndex2 = Int.random(in:0...6)
    }
}


You use random 0...6, so values may be from 0 to 6, included. But a dice has only 6 faces, not 7. How do you handle the extra case ?