Roll a 6-sided die until you have rolled a total of 25 6's.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Asad (Mehrzad) Khoddam
2020년 9월 11일
find(cumsum(randi(6,1,1000)==6)==25,1)
댓글 수: 3
Asad (Mehrzad) Khoddam
2020년 9월 11일
편집: Asad (Mehrzad) Khoddam
2020년 9월 11일
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
2020년 9월 12일
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!