With shuffling cards for a card game.
I iphonedevelop18 macrumors member Original poster Feb 26, 2009 50 0 Apr 4, 2009 #1 With shuffling cards for a card game.
Jeremy1026 macrumors 68020 Nov 3, 2007 2,215 1,029 Apr 4, 2009 #2 iphonedevelop18 said: With shuffling cards for a card game. Click to expand... I actually did something like this for another project (it wasnt cards though.) Code: for (int j = 0; j < numberArray.count; j++) { int randomIndex = [[NSNumber numberWithInt:0 + arc4random() % 52] integerValue]; [numberArray exchangeObjectAtIndex:j withObjectAtIndex:randomIndex]; } So, 1st put the 52 cards into an array, then run that code to shuffle it . It seems to work okay for me.
iphonedevelop18 said: With shuffling cards for a card game. Click to expand... I actually did something like this for another project (it wasnt cards though.) Code: for (int j = 0; j < numberArray.count; j++) { int randomIndex = [[NSNumber numberWithInt:0 + arc4random() % 52] integerValue]; [numberArray exchangeObjectAtIndex:j withObjectAtIndex:randomIndex]; } So, 1st put the 52 cards into an array, then run that code to shuffle it . It seems to work okay for me.
I iphonedevelop18 macrumors member Original poster Feb 26, 2009 50 0 Apr 5, 2009 #3 how do I go about putting the cards into an array?