Archived

This topic is now archived and is closed to further replies.

General Programming Questions

This topic is 5823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

1. How does a computer''s switch-based modus operandi allow for the creation of random numbers? 2. What is the "best" way to shuffle/deal a deck of cards (using C++)?

Share this post


Link to post
Share on other sites
modulus is an operator that shows the remainder of the number
5 % 4 = 1
using somthing like rand()%10 limits the random number from going past 10

By the way...people get cranky if you post a question in the wrong place. Be careful next time.
good luck

Share this post


Link to post
Share on other sites
I''m angry as hell, but I''m gonna help you anyway.

Please note that due to my anger this might not be the best way.

1) Number the cards 1-52
2) Fill an array (bool array) with 52 elements with false
3) Make a new array (the ''deck'')
4) Choose a card and put it into the ''deck'', setting the ''card'' flag to true (in step 2''s array)
5) If the card was already used (i.e. the step-2 array element was true), choose another card w/o putting it into the deck
6) Repeat with step 4 until all 52 cards are happy

p.s. I''m actually not angry.

Share this post


Link to post
Share on other sites