I want to simulate a Monte-carlo simulation and count how many occurences of 2 6s with the the number of rolls to get said success of 2 6s. I tried messing with my code and i can get the number of rolls until 2 6s but the occurence count is fixed at one.
num_trial=10000; % number of trials
num_until_success=1;% number of rolls until 2 6s
counter=[]; % number of consecutive rolls
success_count=0; % counts number of succesful 2 6s
for i=1:num_trial %initializes the for loop
success_count=0;%starts the success count at 0
num_until_success=0; %re-initilize the count before the while loop
while success_count==0 %sets the inequality for the while loop
roll_1=randi(6,1); %simulates one dice rolling
roll_2=randi(6,1); % simulates the second dice rolling
num_until_success=num_until_success + 1; %adds to the variable for each loop thats is unsuccesful
if roll_1==6 && roll_2==6 %sets an if statement and checks that both rolls were 6 via an inequality
success_count=1; %adds to the count if the if statments is true
else
success_count=0;
end
end
end
histogram(num_until_success,10); %plots histogram with 10 bins
xlabel('Number of consecutive rolls until two 6s') % x-axis label
ylabel('Number of occurences') % y-axis label