Get startedGet started for free

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.

This exercise is part of the course

Parallel Programming in R

View Course

Exercise instructions

  • Create a configuration for future_map().
  • Set the seed at 4321 in the configuration.
  • Supply this configuration to future_map().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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)
Edit and Run Code