问题
i know that there are many ways to program a deck of poker cards where value is important after searching on the net.
My problem is that my "deck" of cards is a simple array with value as "card name" (example 1 = Ace of Spades)
Do i randomize my current Array with NSMutableArray and then remove index 0 everytime the card is being "drawn" til the last card?"
回答1:
The standard algorithm is something like this:
a) Populate an array of 52 cards (order not important)
b) Set size variable to 52
c) Pick a random number r in range 0 <= r < size
d) Store the picked card, card[r], as the result
e) Swap card[r] and card[size - 1]
f) decrement size
g) goto c
来源:https://stackoverflow.com/questions/1881146/how-to-program-drawing-from-a-deck-of-card-where-value-and-suit-is-unimportant