The max streak for tails/heads I get is 15 , Am I right?
That is totally going to depend on the sequence of random numbers returned by rand() which is implementation specific.
You're not seeding the random number generator by calling srand(). That means you're going to get the same sequence of pseudo-random numbers every time you run your program. You should call srand() once at the beginning of main(). http://www.cplusplus.com/reference/cstdlib/srand/
Gunnerfunner I only added the srand function and changed the for statement to int m = 1;
Otherwise the code is as was. I assumed because he kept getting the same result it was due to not randomising?
gunnerfunner - yeah I've just ran my rendition and got varying results from 29 to 23
It tossing a coin and counting consecutive nunbers thrown? Or have I misread it?
Surely there is a point/number where no matter how many times you run the loop you will always get around the same result because its random - if you get my meaning
I added code to print out m whenever it gets a new max streak size:
1 2 3 4
if (streak > max_streak) {
max_streak = streak;
cout << "streak length " << max_streak << " ended at m = " << m << '\n';
}
Running it on my PC I get:
streak length 1 ended at m = 4
streak length 5 ended at m = 10
streak length 6 ended at m = 433
streak length 10 ended at m = 511
streak length 12 ended at m = 5244
streak length 13 ended at m = 18151
streak length 16 ended at m = 99349
streak length 20 ended at m = 225161
streak length 22 ended at m = 6404348
streak length 25 ended at m = 21024497
streak length 28 ended at m = 92173082
max streak 28
As you can see, each new record takes nearly an order of magnitude more tosses to set each new record.