how to program drawing from a deck of card where value and suit is unimportant?

三世轮回 提交于 2019-12-24 18:53:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!