Hey guys, I have a coin toss simulation I am trying to run, but the problem is I keep getting only one result instead of a randomized one. I went over the code and it doesn't seem like anything would be out of place. I was hoping for some tips to the problem.
yes agree, srand func early to initialize random generator. if called more than once, srand() will
be active throughout all of main. also:
1 2 3 4 5 6 7 8 9 10 11 12 13
num = rand() % 2 + 1; // to get 1 or 2 only
// sometimes rand() will exceed expected
// did rand() %14+2 before and was getting 15
or could do
num = rand() %1; // where 0 is head and 1 is tails or the opposite
or random(2) could be used
random does (num -1)
an example in one of my languages is random(100), 0 to 99