Reproducible lottery results
You work as a programmer for an online lottery. By law, the winners have to be selected randomly and the selection has to be transparent.
In your workspace you have a list of lottery tickets, ls_tickets
. There are 51 elements in ls_tickets
, one for each US state. Each element of this list contains lottery ticket numbers. In your workspace, you have a function, lottery()
, that randomly selects the winning ticket for each state. You are testing the lottery()
function by applying it to ls_tickets
in parallel using future_map()
. The problem is that the winners are different every time you run this code. The furrr
package has been loaded for you.
Este exercício faz parte do curso
Parallel Programming in R
Instruções do exercício
- Create a configuration for
future_map()
. - Set the seed at
4321
in the configuration. - Supply this configuration to
future_map()
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
lottery <- function(tickets) {
sample(tickets, 1)
}
# Create a configuration for future_map()
config <- ___(
# Provide the seed 4321 to the correct argument
___ = ___)
plan(multisession, workers = 4)
winners <- future_map(ls_tickets, lottery,
# Supply configuration to future_map()
___ = ___)
plan(sequential)