Im a relatively new programmer working on a card game app on Xcode, as of right now I generate a random number to determine which card gets dealt first. Im curious as to how I can prevent the same number from popping up more than once. Lets say the generator picks 52 and the Ace of Spades gets dealt, when its dealing to the next player the generator still has the possibility of picking 52 which wouldn't work because the Ace of Spades has already left the deck.
Heres a sample of my code........
(the random number goes from 27 - 52 because I only have Spades and Hearts so far)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//Dealing Random Cards ------------------------------------------------------------------------------------------------------
self.FirstCard = arc4random() % 26+27;
NSLog(@"Random Number: %i", self.FirstCard);
//Deal First Card --------------------------------------------------------------------
if (self.FirstCard == 52) {
SKAction *DealFirstCard = [SKAction moveToY:40 duration:0.25];
SKAction *DealFirstCard2 = [SKAction moveToX:130 duration:0.25];
SKAction *DealSequence = [SKAction sequence:@[DealFirstCard,DealFirstCard2]];
[self.ASpade runAction:DealSequence];
}
if (self.FirstCard == 51) {
SKAction *DealFirstCard = [SKAction moveToY:40 duration:0.25];
SKAction *DealFirstCard2 = [SKAction moveToX:130 duration:0.25];
SKAction *DealSequence = [SKAction sequence:@[DealFirstCard,DealFirstCard2]];
[self.TwoSpade runAction:DealSequence];
}
if (self.FirstCard == 50) {
SKAction *DealFirstCard = [SKAction moveToY:40 duration:0.25];
SKAction *DealFirstCard2 = [SKAction moveToX:130 duration:0.25];
SKAction *DealSequence = [SKAction sequence:@[DealFirstCard,DealFirstCard2]];
[self.ThreeSpade runAction:DealSequence];
}