w1 <- function() (1:1000)[rbinom(1000, 1, 0.1)==1][1] values <- tabulate(replicate(1000,w1()), 40) plot(1:40, values)