Here i am going to talk about Casino winning strategies. So many games in casino, let’s play DICE
If i throw 3 dices, what is the highest likelihood that a sum will appear ? Is it minimum of sum of 3 or maximum 18 respectively for each time 3 dices are thrown ?
First write a simple function of rolling a pair of dice with equal probability of 1/6.
roll <-function()
{
die<- 1:6
dice<-(sample(die,size=3, replace=TRUE, prob=c(1/6,1/6,1/6,1/6,1/6,1/6)))
sum(dice)
}
roll()
## [1] 12
When i called the roll() function, sum will change each time. It could be 8 or 10 or etc
Now how many times of sum will each appear ? After all we want to guess the highest likelihood of a magic sum right ?
We will use simple qplot (from library(ggplot2)) and replicate function()
I am going to roll 10 times of the dice using replicate function.
roll_many_times <- replicate(10,roll())
Then plot a simple graph of 10 rolls
library(ggplot2)
qplot(roll_many_times, binwidth=1)
However if you stay casino for 24 hours and observe the number of rolls against time, the mean will change.
roll_many_times <- replicate(10000,roll())
Then plot a simple graph of 10000 rolls
library(ggplot2)
hist(roll_many_times, freq=FALSE, col=rainbow(3))
lines(density(roll_many_times), lty=2)
mean(roll_many_times)
## [1] 10.4838
The mean is therefore the likely “the sum of 3 roll dice” will appear if you stay long in Casino to watch.