jeudi 21 novembre 2019

Choosing a random element from a set that has integers and letters c++

I'm trying to have a set that includes {1,2,3,4,5,6,7,8,9,A,B,C} and I want a code that chooses a random entry every time the function is called. This is what I have so far and it's not doing that

string cards = "12345678910AB";
cout << "size is " << cards.size();
for (int i = 0; i < 20; i++) {
    int random = rand() % cards.size();
    cout << "Current hand: " << random << endl;
}

I have the loop to try and see if it pulls any letters but it never did.




Aucun commentaire:

Enregistrer un commentaire