Integrate a function using the Hit-or-Miss Monte Carlo algorithm.
We compute the proportion of points hitting the area under the curve, and the integral can be estimated by the proportion multiplied by the total area of the rectangle (from xmin to xmax, ymin to ymax).
library(animation)
ani.options(interval = 0.2, nmax = 100)
## should be close to 1/6
MC.hitormiss()$est
## [1] 0.1725
## should be close to 1/12
MC.hitormiss(from = 0.5, to = 1)$est
## [1] 0.07874