How to find same values in a randi function
4 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Image Analyst
2024 年 2 月 25 日
I've already done it. You can look at the attached m-file code.
% Finds frequency of 5 card poker hands
% Reference
% https://en.wikipedia.org/wiki/Poker_probability#Frequency_of_5-card_poker_hands
% Theory says
% One pair 42.2569%
% Two pair 4.7539%
% Three of a kind 2.1128%
% Straight (excluding royal flush and straight flush) 0.3925%
% Flush (excluding royal and straight) 0.1956%
% Full house 0.1441%
% Four of a kind 0.0240%
% Straight Flush (excluding royal flush) 0.00139%
% Royal Flush = 0.000154%
Found 421681 "One Pair" in 1000000 hands. That is one in every 2 hands.
Percentage of "One Pair" = 42.168100%. Theory says 42.2569%
Found 47652 "Two Pairs" in 1000000 hands. That is one in every 21 hands.
Percentage of "Two Pairs" = 4.765200%. Theory says 4.7539%
Found 21137 "3 of a kind" in 1000000 hands. That is one in every 47 hands.
Percentage of "3 of a kind" = 2.113700%. Theory says 2.1128%
Found 3461 straights in 1000000 hands. That is one in every 289 hands.
Percentage of straights = 0.346100%. Theory says 0.3925%
Found 1877 Flushes (excluding straight and royal) in 1000000 hands. That is one in every 533 hands.
Percentage of Flushes = 0.187700%. Theory says 0.1956%
Found 1428 Full Houses in 1000000 hands. That is one in every 700 hands.
Percentage of Full Houses = 0.142800%. Theory says 0.1441%
Found 210 "4 of a kind" in 1000000 hands. That is one in every 4762 hands.
Percentage of "4 of a kind" = 0.021000%. Theory says 0.0240%
Found 4 straight flushes (excluding royal) in 1000000 hands. That is one in every 250000 hands.
Percentage of straight flushes = 0.000400%. Theory says 0.00139%.
Found 2 Royal Flushes in 1000000 hands. That is one in every 500000 hands.
Percentage of Royal Flushes = 0.000200%. Theory says 0.000154%
0 件のコメント
その他の回答 (1 件)
Torsten
2024 年 2 月 25 日
Hand = randi(13,[1,5])
arrayfun(@(i)nnz(Hand==i),1:13)
1 件のコメント
Steven Lord
2024 年 2 月 25 日
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!