Skip to content

Instantly share code, notes, and snippets.

@tvladeck
Created February 27, 2018 06:47
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 tvladeck/e7a164dfe70fa765b10c1af64b382b02 to your computer and use it in GitHub Desktop.
Save tvladeck/e7a164dfe70fa765b10c1af64b382b02 to your computer and use it in GitHub Desktop.
set.seed(20180226)
block_mining_times <- rpois(1000, 10) # lambda = 10
max_time <- sum(block_mining_times)
cumulative_times <- cumsum(block_mining_times)
rand_times <- runif(1000, min = 0, max = max_time)
deltas_between_blocks <-
rand_times %>%
sapply(function(t){
time_till_next_block <- min((cumulative_times - t)[which(cumulative_times - t > 0)])
time_from_last_block <- min((t - cumulative_times)[which(t - cumulative_times > 0)])
time_till_next_block + time_from_last_block
})
# > deltas_between_blocks %>% mean
# [1] 10.817
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment