Skip to content

Instantly share code, notes, and snippets.

@jlopezper
Created August 28, 2018 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlopezper/d8244cbbcce01a3c4acebc0fcee10be8 to your computer and use it in GitHub Desktop.
Save jlopezper/d8244cbbcce01a3c4acebc0fcee10be8 to your computer and use it in GitHub Desktop.
Simulation
runs <- 100000
threshold <- 1000
Res = vector(mode = "numeric")
for (k in 1:runs){
i <- 1
v <- vector(mode = "numeric")
while (sum(v) < threshold) {
v[i] <- runif(1,0,1000)
longitud <- length(v)
i = i+1
}
Res[k] <- longitud
}
mean(Res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment