# what is the probability that when three dice are rolled, at least two of the dice have the same value? what is the probability that the value of the third dice roll is strictly between the values of the first two rolls? use simulation to estimate

22 views (last 30 days)
Kevin Junior on 7 Oct 2013
Commented: Youssef Khmou on 9 Oct 2013
I know for sure that I am going to use rand() to simulate the throws but how do I compute the probilities?
Kevin Junior on 9 Oct 2013
thanks !!1 it definitely helped!

James Tursa on 8 Oct 2013
Edited: James Tursa on 8 Oct 2013
First, rand produces a uniform distribution, not integers, so you need to adjust your x, y, and z formulas to turn them into integers with equal probabilities:
x = floor(1 + 6*rand(n,1));
etc.
Or look at randi as Walter has suggested.
As you have coded it, this condition only covers two of the possibilities:
if x(k)== y(k)|| y(k)==z(k)
But what about if the first value matches the third value? That is not covered by your test, so you should modify it to account for this possibility.
Also, this condition you have coded isn't quite correct:
if x(k) < z(k) && z(k) > y(k)
Plug in some sample values and you will see what I mean. Remember you will need to cover the case where x(k) is less than y(k) and also the case where x(k) is greater than y(k).
As to your general question of how to calculate probabilities, you simply count the number of successes and divide that by the number of trials. E.g., start two counters, one for the first test and one for the second test, at the front of your code before you enter the loops:
P = 0;
Q = 0;
Then, inside the first if test do P = P + 1, and inside the second if test do Q = Q + 1;
At the end of your code you can then do this to get the probabilities:
P = P / n; % probability of first condition being true
Q = Q / n; % probability of second condition being true

Ken Atwell on 8 Oct 2013
Kevin Junior on 8 Oct 2013
more like self teaching a concept

Youssef Khmou on 9 Oct 2013
Edited: Youssef Khmou on 9 Oct 2013
i want add one concept, you want to compute a certain probability of dice over N times, throw N dices one time and compute, there is specified term for this concept, anyone?
Youssef Khmou on 9 Oct 2013
yes Mathew !, one of the assumptions of the statistical mechanics .