   Shuffling infinite loop[solved]
  Thanks, this is solved.[Edited by - lefthandman on April 29, 2009 9:44:22 PM]
  First: Fix the width of the codebox in your post!A better way to shuffle the deck is by:1. filling the deck with all cards in order.2. pick a random card out of the deck and move it to the end of the deck3. pick a random card out of the deck excluding the last card (the one that moved there in the previous step) and move it to the end of the deck.4. pick a random card out of the deck excluding the last two cards and move it to the end of the deck5. ... and so on until the remaining part of deck to pick a card from has just one card left.This way it is finite.;  In C++ also:1) fill the deck with all cards in order2) use std::random_shuffle to put them in random orderThat is also probably the longest condition I've ever seen: it fills more than a page and comes with embedded comments? :)   ;  In that gigantic condition, you includernumber[0] == rnumber[0][i-4]Since you're looping from 0..12, but you only change the first four, what happens when i==8? [0][8] and [0][4] are both initialized to 0 previously.Also, you are using negative indices, so long as i<12. Not good.Also, if you need a set of unique numbers, it's better to generate them first and then shuffle them. It's an even easier task if you know the numbers you need.   ;  D'oh, thank you!   ;Quote:Original post by lefthandmanD'oh, thank you!Next time, please don't remove the original problem as others can't from this at a later date.   