why the percentage of even and odd numbers generated by rand() is the same every time?
I wrote this code to figure out how random is the rand() function, maybe there are other ways to figure it out but i did what came to my mind first and with what knowledge i have of c++, but turns out the percentage of even and odd number are 48-52 every time. i ran it with code::block IDE and it's the same every time. I thought the percentage of even and odd numbers would be also random. please help me, what is it that i'm missing here?? #include <iostream> #include <cstdlib> using namespace std; int main() { int even = 0, odd = 0; for(int i = 0; i < 100; i++){ int x = rand(); if(x%2==0){ even++; } else{ odd++; } } cout << odd << " " << even ; return 0; }