I have simply functions to random numbers but there is something wrong with the first one because the results are not correct.
int wylosuj(int a, int b)
{
int wynik=(( std::rand() % b-a+1 ) + a);
return wynik;
}
Second Function (this one gives me the proper result)
int wylosuj(int a, int b)
{
int endNumber=b-a+1;
int startNumber=a;
return std::rand()%endNumber+startNumber;
}
In my main function I have got this line to run the function with arguments:
wylosuj(3,3);
So desired results should be only 3.
Where did I make mistake with first function?
Aucun commentaire:
Enregistrer un commentaire