SHOW:
|
|
- or go back to the newest paste.
| 1 | do {
| |
| 2 | if(!FlipCoin()) {
| |
| 3 | flips.Clear(); | |
| 4 | } | |
| 5 | } while(flips.Count < 10); | |
| 6 | ||
| 7 | /* | |
| 8 | - | The problem is there's a 50% chance that every time the do-loop iterates FlipCoin will be false, and if it is it CLEARS flips causing flips.Count to never be larger than 10. In order for flips.count to get larger than 10 and end the loop you have to get 10 flips in a row...which is like a 1/1024 chance of that to actually happen. And because that's never happening, the do-loop is an infinite loop and it's locking up the unity editor. |
| 8 | + | The problem is there's a 50% chance that every time the do-loop iterates FlipCoin will be false, and if it is it CLEARS flips causing flips.Count to reset back to 0, and to never be larger than 10. In order for flips.count to get larger than 10 and end the loop you have to get 10 flips in a row...which is like a 1/1024 chance of that to actually happen. And because that's never happening, the do-loop is an infinite loop and it's locking up the unity editor. |
| 9 | ||
| 10 | Think of it like trying to flip a real coin and getting heads 10 times in a row. Every time you flip tails you start back at 0. You would be sitting there flipping coins _forever_ | |
| 11 | */ |