#' Takes a probability distribution of events and returns which event happened based on
#' those probabilities
#'
#' @param distribution A vector p where p[i] denotes the relative probability of event i
#' @return An index i (to denote that event i took place)
#' @export
#'
pick_random_event <- function(distribution)
{
distribution <- cumsum(distribution/sum(distribution))
r <- runif(1)
return(1 + sum(distribution < r))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.