Not sure exactly what you are asking.
Perhaps you need to think in terms of a real physical pack of cards. You select one card at random from the deck, and pull it out. Now you have that card placed separately somewhere, and the deck itself has reduced in size as there is one card fewer.
When you emulate this in a program, it breaks down into a series of steps, which need to be done in a specific order.
so far i know that i have to find the length of the card. |
that is, how many cards are in the deck. You need that in order to generate a random number within the correct range.
but i don't know why i have to save the location onto another variable |
Well, having chosen a card by number, there are two actions required:
1. make a copy of the card which was stored in the vector
2. erase that element of the vector.
as a consequence of (2) the vector size will be reduced by one as well.
Either of these alone would not be sufficient. If you only erase it, then you no longer have access to that element so don't know what to return. Or if you only return that card but don't erase it, then later that same card may be chosen again, which doesn't correctly model the real world, where a card cannot be in two places at the same time.