Roll a 6-sided die until you have rolled a total of 25 6's.
2 views (last 30 days)
Show older comments
Hello,
I am trying to wrtie a script to roll randi(6) and loop until it has reached 25 sixes and then count how many rolls it took. Help please.
0 Comments
Accepted Answer
More Answers (1)
Asad (Mehrzad) Khoddam
on 11 Sep 2020
find(cumsum(randi(6,1,1000)==6)==25,1)
3 Comments
Asad (Mehrzad) Khoddam
on 11 Sep 2020
Edited: Asad (Mehrzad) Khoddam
on 11 Sep 2020
Yes, you are right. Simply if it happens, you can try again
The probability is 1.536e-48 (it happens once in 6.5e47 tries)
Walter Roberson
on 12 Sep 2020
You wouldn't quite just try again... you would have to subtract off the number of 6's that you got up to that point, and you would have to add the number of attempts you already made to the index.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!