I have a problem with the small game that I 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 running 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)) makes it dependent on the current time. But how would I make it "more" random, since I don't want the stuff to happen that I mentioned above.
First time I ran it the result was 11, after running it again (after guessing the right number) , it was still 11, even though the time changed.
int TheNumber = rand() % 100 + 1;rand()are notoriously not random.rand()might be out of the scope of current Q and OP's experience, don't you think?