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.
Diese Übung ist Teil des Kurses
Parallel Programming in R
Anleitung zur Übung
- Create a configuration for
future_map()
. - Set the seed at
4321
in the configuration. - Supply this configuration to
future_map()
.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
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)