How to find same values in a randi function
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
Hand = randi(13,[1,5])
arrayfun(@(i)nnz(Hand==i),1:13)
1 comentario
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)
Categorías
Más información sobre Card games en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!