Computer Science Canada Rand.Int help |
Author: | KONjbnj [ Fri Apr 28, 2006 1:26 pm ] |
Post subject: | Rand.Int help |
I have two variables that I am giving a random number from 1-13. I want it so that if the first variable is say, 6, the second variable can't be five. I though of using an 'if' statement, but I just get even more confused. |
Author: | Albrecd [ Fri Apr 28, 2006 1:32 pm ] | ||
Post subject: | |||
Use a for loop for your if statement between the two rolls.
By the way, what are you using this for? |
Author: | KONjbnj [ Fri Apr 28, 2006 1:34 pm ] |
Post subject: | |
Whoops, I mean that the second variable can't be the same as the first. |
Author: | KONjbnj [ Fri Apr 28, 2006 1:35 pm ] |
Post subject: | |
And it's for some blackjack game I gotta do for class. I want it so that if the first card is Ace of Spades, no other card can be Ace of Spades. |
Author: | Albrecd [ Fri Apr 28, 2006 1:38 pm ] |
Post subject: | |
Wow, I feel stupid . Just get rid of the line: Albrecd in his stupidity wrote: for loop determining what second randint can't be |
Author: | KONjbnj [ Fri Apr 28, 2006 1:40 pm ] | ||
Post subject: | |||
Thanks, I think I got it. PC1 and 2 is first and second card. PC1S and 2S is the first and second suit (1 = Spades, 2 = Hearts, 3 Clubs, 4 = Diamond)
|
Author: | Albrecd [ Fri Apr 28, 2006 1:59 pm ] | ||
Post subject: | |||
Quote:
It should be or, rather than and. |
Author: | Cervantes [ Fri Apr 28, 2006 2:56 pm ] | ||
Post subject: | |||
To return to the original question for a moment, there's no need to have a loop. Why would you possibly want to use a loop to generate a second random number when you can do it on the first try? Say the first roll is 6. The second roll must be one of the set {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13}. There's 12 digits there. Thus, we can "roll a 12-sided die" and use that value. However, if the value on this roll is a 6, we return 13.
|