No you are generating a random number 340000 times.
Look at your odds, you generate a random number X in the range 0 <= X < 10000. So the change it is 0 is 1/10000. If you are generating 340000 that means you can expect around 340000 * 1/10000 or 340000 / 10000 or 340 to be 0.
This is born out if you add just a little output to your program like this
- #include "stdlib.h"
-
#include "stdio.h"
-
#include "time.h"
-
-
int main()
-
{
-
int i = 0;
-
int zero = 0;
-
-
srand(time(NULL));
-
-
while(i<3400000)
-
{
-
int r_number= rand() % 10000;
-
if(r_number == 0)
-
{
-
// do something
-
printf("0 at %d\n", i);
-
zero++;
-
}
-
-
i++;
-
}
-
-
printf("Total 0: %d\n", zero);
-
-
return 0;
-
}
-
If you want 10,000 0 then you need to either alter the the number of iterations of the while loop or you need to alter the probability of getting a zero by altering the range of the random numbers you are generating or you need to alter both such that
<NumberOfIterations> * <ProbabilityOf0> = 10000