So, I have made a program that simulates things and in it I noticed that the c++ function rand() seemed to generate low numbers too often, so I tried to test it.
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <time.h>
#include <cfloat>
#include <iomanip>
using namespace std;
int main(){
srand(time(NULL));
int qwerty=0;
for(int i=0; i<10000000;i++){
if(rand()%10000<2800){
qwerty++;
}
}
cout << qwerty << endl;
return 0;
}
If I ran the file with this "for tester" in it I would get consistently a number near 3400000, or 34%, which is near to the 34% I had seen appear inside my real program, the problem is that the output should be near 2800000 or 28%.
I then tried to run this "for tester" on a new project(the same I wrote here) where only the libraries and the srand(time(NULL)) were present, same output.
I then tried to copy this file inside an online compiler, this time instead of 3400000 I got the correct number 2800000.
I can't find why this is happening, anyone who knows?
Additional info: I am using dev-c++ as a IDE with the TDM-GCC 4.9.2 64bit release and the ISO C++11, If I take the executable generated by my computer and run it in another one I get the same 34% result, Windows 10 is the operating system. This problem happens also if I use different numbers.