mardi 23 juillet 2019

Why the rand() command just generates positive integers and on a specific range even if i don't set a range

I am trying to fill a vector with 5000 random numbers. Each number is an integer. But i am wondering why rand() only gives unsigned integers and also it never gives the max values that an integer can hold. Is there a reason for that?

unsigned seed = time(0);
srand(seed);

vector<int> vect(5000);

for (int i = 0; i < vect.size(); i++)
{
    vect[i] = rand();
}




Aucun commentaire:

Enregistrer un commentaire