Not sure why my code results in a wrong figure. I am trying to simulate 2 dice rolls and counting how many times it takes to roll 2 6s out 10000 trials.

3 views (last 30 days)
num_trial=10000;
num_until_success=1;
counter=[];
success_count=0;
for i=1:num_trial
success_count=0;
num_until_success=0;
while success_count==0
roll_1=randi(6,1);
roll_2=randi(6,1);
num_until_success=num_until_success + 1;
if roll_1==6 && roll_2==6
success_count=1;
end
end
end
histogram(success_count,10);
xlabel('Number of consecutive rolls until two 6s')
ylabel('Number of occurences')
  2 Comments
Enkhdul Batkhuyag
Enkhdul Batkhuyag on 28 Apr 2020
This the figure I get from my code but the Y-axis is fixed to one and doesn't track the number of occurences per number of rolls until 2 6s

Sign in to comment.

Accepted Answer

Mrutyunjaya Hiremath
Mrutyunjaya Hiremath on 28 Apr 2020
Hello Enkhdul Batkhuyag,
Try this one -
num_trial=10000;
num_until_success=0;
for i=1:num_trial,i
roll_1=randi(6,1);roll_1
roll_2=randi(6,1);roll_2
if roll_1==6 && roll_2==6
num_until_success=num_until_success + 1;
end
end
disp(num_until_success)
  8 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!