int roll(int low, int high)
{
int range = high - low + 1;
srand(time(0));
int result;
result = rand() % range + low;
return result;
}
1 2 3 4 5 6 7 8
bool isFight(int percent)
{
int result = roll(0, 99);
if (percent > result)
returntrue;
elsereturnfalse;
}
The type of data I want for isFight is a number between 0 and 100 that gives the approximate percent chance of the condition being satisfied. I tested my program using isFight(50), which should be about a 50% chance, but the condition ends up being satisfied far less than 50% of the time. Any suggestions?
Only use srand() once at the beginning of your program. Different pseudo-random sequences are not guaranteed to be mutually random. (You keep resetting yours every time you roll().)
But I'll agree with Somelauw: you'll find a much better random number generator on the web.