蒙特卡罗方法计算pi

import scala.math.random

object LocalPi {
def main(args: Array[String]) {
var count = 0
for (i <- 1 to 100000000) {
val x = random * 2 - 1
val y = random * 2 - 1
if (x*x + y*y <= 1) count += 1
}
println(s"Pi is roughly ${4 * count / 100000000.0}")
}
}
原文地址:https://www.cnblogs.com/timlong/p/9996392.html