Learn R Programming

tigerstats (version 0.3.2)

make_game: Play with a Discrete Random Variable

Description

Makes a function that simulates a game based where your winnings are the sum of a specified number of plays of a discrete random variable with a specified distribution.

Usage

make_game(outcomes, probs, plays)

Arguments

outcomes

numerical vector of possible values of the random variable

probs

numerical vector giving the probability distribution

plays

number of times the random variable is simulated

Value

a function of a single parameter n, with default value 1. n is the number of times you simulate the net winnings.

Examples

Run this code
# NOT RUN {
play_game <- make_gmae(
  outcomes = c(-1, 0, 5)
  probs = c(0.4, 0.5, 0.1)
  plays = 2000
)
## Play "plays" times, get net winnings:
sampler()
## Play "plays" times again:
sampler()
## Play "plays" times, a third time:
sampler()
## 1000 more simulations of the net winnings:
sampler(n = 1000)
# }

Run the code above in your browser using DataLab