Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
segue example
estimatePi <- function(seed){
numDraws <- 1e6
r <- .5 #radius... in case the unit circle is too boring
x <- runif(numDraws, min=-r, max=r)
y <- runif(numDraws, min=-r, max=r)
inCircle <- ifelse( (x^2 + y^2)^.5 < r , 1, 0)
return(sum(inCircle) / length(inCircle) * 4)
seedList <- as.list(1:1e3)
myCluster <- createCluster(20)
myEstimates <- emrlapply( myCluster, seedList, estimatePi )
myPi <- Reduce(sum, myEstimates) / length(myEstimates)
format(myPi, digits=10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.