Assistance with Dice Simulation script
Ältere Kommentare anzeigen
The objective is to create a simulation to count the number of rolls it takes to roll two dice until both show the number 6. The script is supposed to count the number of rolls it takes for a total of 10000 trials.
NumberTrials=10000;
rollcount=0;
Counter=[];
success=0;
for i=1:NumberTrials
success=0;
rollcount=0;
while success==0
Roll1=randi(6,1);
Roll2=randi(6,1);
rollcount=rollcount+1
if Roll1==6 && Roll2==6
success=1
end
end
end
This is the code i have. The problem i am having is that the script continues to run past 10000 trials and I dont know how to store the number of rolls it takes until a success into a vector. Any help would be appreciated!
Antworten (1)
Walter Roberson
am 27 Apr. 2020
After the while loop:
rollcounts(i) = rollcount;
Also,
rollcount=rollcount+1
I recommend changing that to
rollcount=rollcount+1;
and
success=1
to
success=1;
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!