craps {simEd} | R Documentation |
Monte Carlo Simulation of the Dice Game "Craps"
Description
A Monte Carlo simulation of the dice game "craps". Returns a point estimate of the probability of winning craps using fair dice.
Usage
craps(nrep = 1000, seed = NA, showProgress = TRUE)
Arguments
nrep |
Number of replications (plays of a single game of craps) |
seed |
Initial seed to the random number generator (NA uses current
state of random number generator; |
showProgress |
If |
Details
Implements a Monte Carlo simulation of the dice game craps played with fair dice. A single play of the game proceeds as follows:
Two fair dice are rolled. If the sum is 7 or 11, the player wins immediately; if the sum is 2, 3, or 12, the player loses immediately. Otherwise the sum becomes the point.
The two dice continue to be rolled until either a sum of 7 is rolled (in which case the player loses) or a sum equal to the point is rolled (in which case the player wins).
The simulation involves nrep
replications of the game.
Note: When the value of nrep
is large, the function will execute
noticeably faster when showProgress
is set to FALSE
.
Value
Point estimate of the probability of winning at craps (a real-valued scalar).
Author(s)
Barry Lawson (blawson@bates.edu),
Larry Leemis (leemis@math.wm.edu),
Vadim Kudlay (vkudlay@nvidia.com)
See Also
Examples
# set the initial seed externally using set.seed;
# then use that current state of the generator with default nrep = 1000
set.seed(8675309)
craps() # uses state of generator set above
# explicitly set the seed in the call to the function,
# using default nrep = 1000
craps(seed = 8675309)
# use the current state of the random number generator with nrep = 10000
prob <- craps(10000)
# explicitly set nrep = 10000 and seed = 8675309
prob <- craps(10000, 8675309)