Skip to content

Instantly share code, notes, and snippets.

@heavywatal
Created March 2, 2020 17:22
Show Gist options
  • Save heavywatal/e73baf583ce5ff6d8b8526dc34eaa6e6 to your computer and use it in GitHub Desktop.
Save heavywatal/e73baf583ce5ff6d8b8526dc34eaa6e6 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(furrr)
library(future)
future::plan("multicore")
L = 1000
M = 100
N = 200
w = rgamma(L, 1)
prob = w / sum(w)
simulate = function(L, M, N, prob) {
stones1 = sample(seq_len(L), M, replace = FALSE, prob = prob)
stones2 = sample(seq_len(L), N, replace = FALSE, prob = prob)
sum(stones1 %in% stones2)
}
x = furrr::future_map_int(rep(L, 10000), simulate, M = M, N = N, prob = prob)
tibble::tibble(x) %>%
ggplot(aes(x)) +
geom_bar()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment