In [1]:
val NUM_SAMPLES = 10000
val count = sc.parallelize(1 to NUM_SAMPLES).filter { _ =>
  val x = math.random
  val y = math.random
  x*x + y*y < 1
}.count()

println(s"Pi is roughly ${4.0 * count / NUM_SAMPLES}")


Pi is roughly 3.1388
NUM_SAMPLES: Int = 10000
count: Long = 7847

In [ ]: