I'm having trouble with the shuffleDeck() function. My problem is that it compiles, builds, and checks out, but when I try and run my full program, it stalls, and won't finish running no matter how long I leave it be. I've rewritten it twice, and have no idea what the problem is. Here's the code:
Never mind, found it. cardRank never reaches 14! Thanks for your help JLBorges! After comparing output from random shuffle and my function, I've decided to use random shuffle, since it's more random.
Thanks JLBorges! My code works now. But I was wondering if you could shed light on how come my own code doesn't work? Thanks for your help so far!
If you seed the random number generator with the same seed you will get the same sequence of random numbers from rand(). std::time(0) returns the time in seconds so if you do std::srand(std::time()) each time randomNum is called you will get the same number for all calls within the same second. That would explain why your code takes so long to finish. Even in the best case you would have to wait at least 52 seconds.
Peter87, I've checked randomNum, and everything is fine. I've made it so it follows the example given on this site for generating random numbers with the c libraries. JLBorges, this is the working implementation of the shuffleDeck function before I changed it in favor of the random_shuffle function.