how to program drawing from a deck of card where v

2019-08-20 18:20发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-20 19:12

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
查看更多
登录 后发表回答