MATLAB: Dice with changed probabilites

probability

Hello again !
I have a small problem with my code. I had to create a dice with changed probabilites for each number where the number 3 had a probability of 1/5 (20%). The task was to count the number of times i get the number 3-three times in a row.
The probability for this should be in theory 0,2*0,2*0,2=0,008=0,8%. That means i should get my three 3s every 125 throws on average. The problem now is when i throw my dice now like a 100000 times i get a probability of only 0,15% and i cant find the reason why. Is my code wrong or is my theoretic probability wrong?
I coded it like this:
clc
clear all;
lastthrow = 0;
threetimescounter = 0;
counterbacktoback = 0;
wurf = 0;
for k = 1:1000000
if rand() <= 1/5
wurf = 3;
if lastthrow == wurf
%counter nacheinander gewürfelte 3
counterbacktoback = counterbacktoback + 1; %Inkrement, bis 3 erreicht wird, dann geht ein DREIERBLOCK Counter hoch. und das letzte dreierglied wird direkt weggenommen.
if counterbacktoback == 3
threetimescounter = threetimescounter + 1;
counterbacktoback = counterbacktoback - 1; %Dekrement, weil der Letzte nichtig wird, und die ersten zwei 3er wieder auf den hypothetischen 4. 3er hoffen, der anschliessend mit den 2 letzten eine dreiergruppe darstellen koennte.
end
else
counterbacktoback = 0;
end
else
wurf = 0;
end
lastthrow = wurf;
end
pthree3s=(((1/5)*(1/5)*(1/5)))*100;
pthree3ssimul= (threetimescounter/1000000)*100;

Best Answer

0.8% is the probability of getting three 3's in a throw of three dice. It is not the probability of the number of three 3's in a row in a large number of throws as you are computing. Also you are counting four 3's in a row as two three 3's in a row, five 3's in a row as three 3's in a row, etc. So some of those 3's get counted multiple times in your program. Bottom line is you are comparing apples to oranges with your assessment vs your computation. What is the wording of the actual assignment? What are you actually supposed to be computing? Because the actual computation you are doing does not match the 0.8% assessment.
Related Question