The result of the random function is uniformly distributed between 0 and 2. Which means the output is either 0
, 1
, or 2
with 33% probability each. You are testing for <= 1
, which means you have a 67% probability of accepting the request, which is around 666K per million.
To solve your problem, you need to exclude the lower bound from the interval, change the computation of result to:
result = (rand()%(hi_num-low_num+1))+low_num;
Or you might want to exclude the upper bound instead, depending on what you need. Your statement "This means at every 2 iterations, there should be 1 request incoming" is not consistent with randomly picking 2 numbers out of a set of 3.