int Prob (int num)
Cnc=(rand() % MAX)+1;
if (Cnc <= num)
When MAX is 10000 and num is 5000, the experimental probability of the function returning 1 is almost always between 0.55 and 0.53, even though it should be very close to 0.5 when one trial consists of running it 10000 times. I really don't understand why this is happening. I probably won't be using the function enough for it to actually make a difference, but it still bothers me for some reason. Any help would be appreciated.
I see what the problem is, your OS must be Windows (otherwise how would you compile "void main"?), and RAND_MAX there is only 32767.
Instead of rand() % MAX, try (double)rand() / RAND_MAX * MAX or C++ random number machinery (std::uniform_int_distribution etc)