Created
March 2, 2020 17:22
-
-
Save heavywatal/e73baf583ce5ff6d8b8526dc34eaa6e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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