I have this bit of code when trying to create a random number between n and n^2, and somehow it sometimes produces a negative number. I've checked rand() and time(NULL) and both of them produce a positive number, so how can it be possible for it to produce a negative number as the result?? I'm suppose to generate many numbers to store into an array, but somehow only the first few numbers are negative.
int randomNum = (((rand()*time(NULL))%(n*n-n))+n);
Aucun commentaire:
Enregistrer un commentaire