My take on this would be
#include <iostream>
int main()
{
for( int i = 0; i < 20; ++i) {
std::cout << (char) ((random() % (int('Z') + 1)) + int('A')) << '\n';
}
}
This seems to be very straight forward. You generate a number, that is between everything lower or equal to Z
and greater or equal to A
. If you play with it, you will find that there are also other chars generated. Why is that?
Aucun commentaire:
Enregistrer un commentaire