Article View: comp.std.c++
Article #155FULL HOUSE
From: Peter Pui Tak Chiu
Date: Sun, 13 Sep 1992 14:43
Date: Sun, 13 Sep 1992 14:43
89 lines
2835 bytes
2835 bytes
hi everyone,
i am trying to find the probability of getting a hand of full house from a
shuffled deck of 52 cards.
theoretically, the probability (i think) is:
(13 * 4C2) * (12 * 4C3)
----------------------- = 0.001440576
52C5
but i wrote a c program to calculate this probability and the results turn
out to be very different.
here is part of the results i have:
* the first column denotes the number of trials
* the second column denotes the probability obtained so far
5400000 0.00420815
5410000 0.00420758
5420000 0.00420867
5430000 0.00420829
5440000 0.00420937
5450000 0.00421046
5460000 0.00421154
5470000 0.00420987
5480000 0.00420967
5490000 0.00420765
5500000 0.004208 ..... this means after 5500000 trials, the prob. is 0.004208
from these results, i conclude that the probability would be pretty much around
0.00421 which is very different from the theoretical value.
does anyone know why???
i have included the program i wrote. it is written in C++ and is very crude...
please try it and give me some feedback.
thanx a lot!
pete
// To calculate the probability of getting a full house
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
int BAD,hand[5]; // BAD when the hand dealt is illegal
// e.g. 5 of the same kind.
// hand is an array holding the cards dealt
long COUNTER=0, GOOD=0; // COUNTER = # of trials
// GOOD = # of full house dealt
void init(){
for(int i=0;i<5;i++)hand[i]=rand()%13; // deal the cards
}
int fullhouse(){ // determine if fullhouse or illegal
int counter[13],flag3=0,flag2=0;
BAD=0;
for(int i=0;i<13;i++)counter[i]=0;
for(i=0;i<5;i++)counter[hand[i]]++;
for(i=0;i<13;i++){
if(counter[i]==3)flag3++; // detect for 3 of a kind
if(counter[i]==2)flag2++; // detect for a pair
if(counter[i]>4)BAD=1;} // detect for a bad hand
return((flag3==1) && (flag2==1));
}
main(){
srand((unsigned)time(NULL)); // initialize random seed
while(1){
init(); // deal the cards
if(fullhouse())GOOD++; // if a FULLHOUSE is dealt, increment
// GOOD
if(!BAD)COUNTER++; // if the hand dealt is legal
// increment COUNTER
if(!fmod(COUNTER,10000))cerr<<COUNTER<<" "<<double(GOOD)/COUNTER<<"\n";
// print out the result every 10000 trials in the format:
// [ # of trials ] [ probability obtained so far to get full house ]
}}
Technical Details
Message-ID:
<1992Sep13.144341.24950@wuecl.wustl.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!eclnews!cec1!ppc1Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!eclnews!cec1!ppc1 From: ppc1@cec1.wustl.edu (Peter Pui Tak Chiu) Subject: FULL HOUSE Message-ID: <1992Sep13.144341.24950@wuecl.wustl.edu> Sender: usenet@wuecl.wustl.edu (Usenet Administrator) Nntp-Posting-Host: cec1 Organization: Washington University, St. Louis MO Date: Sun, 13 Sep 1992 14:43:41 GMT Lines: 89