OK then. But since you still need the magic 52 in many places, having a static const that represents the size of the whole deck wouldn't hurt.Quote:
I am going to use this code for a console based BlackJack game, and i am using the DeckSize variable to keep track of how many cards are left in the deck after i draw the top one, that is also why i didn't declare it as a constant.
I meant you can use it as a local variable where you need it. But don't make it a data member of the class. When you hold a real deck of cards in your hand, do you somehow feel that Seconds is a part of it?...Quote:
About the time_t variable: The code i used is just something i basically copied from the FAQ on this site, i figured there would be nothing wrong with it then. I'll make sure i get rid of it though.
I hardly think that 52 is a "magic" number in a program which plays a card game. Making it a macro or constant might imply that it could be changed to some other value.
But you can easily make a typo and have an array of size 5 that the compiler never catches. Its not a big deal but I would probably use the constant not the literal.
>> Daved may be referring to the fact that if (i + 1) in above statement is not a factor of RAND_MAX, the results tend to be biased but I don't think it would make that much difference here.
No, I wasn't referring to that. I agree that such an issue is not important for a toy application. I was referring to potential for something like the 3,4,5 thing mentioned, and basically saying what you said, the index calculation is way too complicated.
However, if you did want to make a real game that people play and make or bet real money with, then you would of course have to use a totally different and much more advanced random number generation scheme. There was an online poker site many years ago that tried to write a random shuffling algorithm like this that they thought was correct. Turns out it had tons of flaws and some guys were able to write a program that knew everybody's cards as they were playing.
One of the wonderful things about change, is that its so often unpredictable :)
by the way, have you never played a game which uses the Jokers? That would make your deck a size of 54..
Besides, even if it were a number which couldn't change (such as PI, or Gravity on planet earth) as others have mentioned, leaving literals lying around your code is undesirable.
.. Another good example is NULL, which is always 0, however, when defining a null pointer, which one would you use..?
>> Another good example is NULL, which is always 0, however, when defining a null pointer, which one would you use..?
Just curious, when would you use (void*)0 or is that equivalent to 0? I did some googling but only found more confliciting discussions. Could someone explain the differences if any?
>> when would you use (void*)0 or is that equivalent to 0?