I have a schooltask where I'm about to do a function whom calculate how many thows its need to get yatzy with five dices.
I have done it pretty good I think, but with 50000 results I get the average throws to ~12 when it should be 191283/17248=*11.0902*
What have I done bad? I have looked over it alot and cant find anything wrong.
function [nr_throws] = nr_throws()throw=[1,5]; % Matrix for 5 dices
nr_throws=1; % First throw
most_common=mode(throw); % Most occured dice in the throw
for dice=1:5 throw(dice)=ceil(6*rand); % Randomize the first throw
endwhile max(std(throw))~=0 % Controll that the first throw not is yatzy
for dice=1:5 if throw(dice)~=most_common throw(dice)=ceil(6*rand); % Randomize the throws that don't occur the most times
end end nr_throws=nr_throws+1; % New throw done
most_common=mode(throw); % Controlls the most occured throw again
end
Calculate the mean with:
function [mean] = mean()i=1;up_to=50000;value=0;while i <= up_to value=value+nr_throws(); i=i+1;endmean=value/up_to;
Best Answer