nico-s
6/7/2017 - 7:12 PM

ViewController.swift

func computeMonteCarloSerial(iterations: Int) {
    for _ in 0...iterations {

        let (x, y) = (drand48() * 2 - 1, drand48() * 2 - 1)
        let point = UIView(frame: CGRect(x: 3 * (x + 1) * 50, y: 3 * (y + 1) * 50, width: 3, height: 3))

        if x * x + y * y <= 1 {
            nPointsInside += 1
            point.backgroundColor = UIColor.red
        } else {
            point.backgroundColor = UIColor.blue
        }

        DispatchQueue.main.async {
            self.monteCarloGraph.addSubview(point)
        }
    }
}