dimanche 12 juillet 2020

Why can't I use rand() with the size of an array?

I am trying to generate a number between 0 and the size of an array. There is my code but the output is always 2. Please help me.

string motMystere = ("Bonjour");
int tailleMotMystere (0);
tailleMotMystere = motMystere.size();
srand(time(0));
int nombreRandom = 0;

nombreRandom = rand() % tailleMotMystere;
cout << nombreRandom << endl;



Aucun commentaire:

Enregistrer un commentaire