vendredi 26 février 2021

Why is rand() giving me negative numbers?

I'm trying to make it so that rand_draw holds a random positive number between 0-8. But this code keeps giving negative numbers on some iterations. What's happening?

srand(time(0));
int draw_count = 8;
int rand_draw = (2 * rand()) % draw_count;
cout << rand_draw << endl;



Aucun commentaire:

Enregistrer un commentaire