Hello,
I'm trying to figure out a way to simulate the shuffling a deck of cards. At the moment I have a vector that holds all 52 cards in the deck. I was thinking of having a for loop and for each iteration generating a random number and then taking the card in the vector being pointed to by the iterator and adding it to a new vector in the position generated by the random number. This should work however, it isn't really efficient since often times the space in the shuffled deck (determined by the random number) will be occupied and the algorithmn will have to try again and generate a new random number until it finds a position in the vector that is unoccupied. If anyone has any ideas on a better algorithmn I would appreciate hearing from you.
Thanks
I'm trying to figure out a way to simulate the shuffling a deck of cards. At the moment I have a vector that holds all 52 cards in the deck. I was thinking of having a for loop and for each iteration generating a random number and then taking the card in the vector being pointed to by the iterator and adding it to a new vector in the position generated by the random number. This should work however, it isn't really efficient since often times the space in the shuffled deck (determined by the random number) will be occupied and the algorithmn will have to try again and generate a new random number until it finds a position in the vector that is unoccupied. If anyone has any ideas on a better algorithmn I would appreciate hearing from you.
Thanks