How to find same values in a randi function
显示 更早的评论
RunTotal = 100000;
NoPair = 0;
OnePair = 0;
TwoPairs = 0;
ThreeofKind =0;
FullHouse = 0;
FourofKind = 0;
FiveofKind = 0;
for i = 1:RunTotal
Hand = randi(13,[1,5])
I am trying to program the probability of getting pairs, full houses, and of kinds of a poker game. I want to use a randi function to generate the 5 card hand, but I cannot seem to figure out how to "read" the randi ouput and calculate how many pairs, full houses and of kinds. Any help is appreciated.
采纳的回答
更多回答(1 个)
Hand = randi(13,[1,5])
arrayfun(@(i)nnz(Hand==i),1:13)
1 个评论
Alternately you could use histcounts instead of the arrayfun call.
Hand = randi(13,[1,5])
[counts, edges] = histcounts(Hand, 1:14)
Note that the last edge is 14. If it were 13 the last bin would count both 12s and 13s in the data (as it would represent the closed interval [12, 13].) With the last edge being 14 the last bin represents [13, 14] and the next-to-last bin represents [12, 13). Alternately you could specify a BinMethod and BinLimits, though the bin edges aren't as nice (unless you round them.)
[counts2, edges2] = histcounts(Hand, BinMethod="integers", BinLimits = [1 13])
edges2r = round(edges2)
类别
在 帮助中心 和 File Exchange 中查找有关 Card games 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!