I have a problem with the small game that iI made.
#include "stdafx.h" #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { int span = 100; srand(time(0)); int TheNumber = static_cast<double> (rand()) /RAND_MAX * (span -1) +1; cout << "You need to guess the number between 1 and " << span << endl; int mynumber; int numberofAttempts = 0; do { cout << ++numberofAttempts <<" Attempt: "; cin >> mynumber; if (mynumber > TheNumber) cout <<"Lower!" << endl; else if (mynumber < TheNumber) cout <<"Higher!" << endl; } while (mynumber != TheNumber); cout << "SUCESS!!!" << endl; return 0; } The game is supposed to generate a random number between 0-100 and you are supposed to guess it. After runingrunning this code 15-20times the same numbers generated some even 8 times (the number 2 in my case).
I know that there is no absolute random number and that it uses some math formula or something to get one.I know that using srand(time(0))srand(time(0)) makes it dependantdependent on the current time. But how would iI make it "more" random, since I don't want the stuff to happen that iI mentioned above.
First time iI ran it the result was 11, after runingrunning it again (after guessing the right number) , it was still 11, even though the time changed.