I am working on a coin toss program. When I run this code, it returns 2, 100 times. Why is not randomly returning 1's and 2's? (Thank you for helping me?
Do not call srand() multiple times. srand() sets the RNG to a particular starting point. Calling srand() repeatedly can cause the RNG to return the same random numbers. srand() should be called ONCE at the beginning of main(). http://www.cplusplus.com/reference/cstdlib/srand/
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you only call it one time, how it is going to pick a new number?
srand() and rand() perform two different functions. Think of random numbers as a very large sequence of non-repeating numbers. srand() determines your starting point in the sequence, rand() gives you the next number from the sequence. If you call srand() multiple times, you're setting the starting point to the same place in the sequence and a subsequent call to rand() will give you the same number from the sequence.
Apparently the request to use code tags went over your head. You will find people here are much more willing to help you if you use code tags.