`x<-runif(1,0,P/2)` (`x: [0, P/2]`)`if(x
R vectorbuffon <- function(n) {
L <- 1; P <- 2
x <- runif(n, 0, P/2)
proj <- sin(runif(n, 0, pi/2))*L/2
2*L*n/(P*sum(proj > x))
}
for(n in 10^c(1:8)) {
cat(sprintf("n = %9d, %f\
", n, buffon(n)))
}
n = 10, 10.000000
n = 100, 2.857143
n = 1000, 3.115265
n = 10000, 3.138732
n = 100000, 3.124219
n = 1000000, 3.140556
n = 10000000, 3.139620
n = 100000000, 3.142656