🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Peter Pui Tak Chiu Sun, 13 Sep 1992 18:53
FULL HOUSE (REVISED)
#327
Author: Peter Pui Tak Chiu
Date: Sun, 13 Sep 1992 18:53
56 lines
1549 bytes

// this previous version of this program assumes that we are drawing from
// an infinite deck.  (which is a bug).

// now this version has no such problem...
// but still the probability is around 0.004...
// which is four times the theoretical value 0.001441

// what's wrong???!!!

#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>

static int hand[5];
long COUNTER=0, GOOD=0;

int getRandom(){
int n,BAD=1;
while(BAD){
n=rand()%52+1;
for(int i=0;i<5;i++){
	int FLAG=0;
	if(n==hand[i])FLAG=1;
	if(!FLAG)BAD=0;
	}}
return(n);
}

void init(){
for(int i=0;i<5;i++)hand[i]=0;
for(i=0;i<5;i++)hand[i]=getRandom();
for(i=0;i<5;i++)hand[i]=hand[i]%13;
}

int fullhouse(){
int counter[13],flag2=0,flag3=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]==2)flag2++;
	if(counter[i]==3)flag3++;
	}
return(flag2&&flag3);
}

main(){
randomize();
while(1){
COUNTER++;
init();
if(fullhouse())GOOD++;
if(!fmod(COUNTER,10000))cerr<<COUNTER<<double(GOOD)/COUNTER<<"\n";
}}
Re: FULL HOUSE (REVISED)
#348
Author: Arthur Rubin
Date: Tue, 15 Sep 1992 21:27
25 lines
1527 bytes
In <1992Sep13.185343.26823@wuecl.wustl.edu> ppc1@cec1.wustl.edu (Peter Pui Tak Chiu) writes:



>// this previous version of this program assumes that we are drawing from
>// an infinite deck.  (which is a bug).

>// now this version has no such problem...
>// but still the probability is around 0.004...
>// which is four times the theoretical value 0.001441

The program looks more or less correct, although I only know C rather than
C++ so I can't verify the output line, but...

The low order bits of random numbers are freqently systematic.  If, for
instance, the low 2 bits of rand move systematically among the suits with
period 4, and, assuming the remaining bits are sufficiently random
(possibly true), we would have the probablity of a full house

(2/13)^3 = .00364
--
Arthur L. Rubin: a_rubin@dsg4.dse.beckman.com (work) Beckman Instruments/Brea
216-5888@mcimail.com 70707.453@compuserve.com arthur@pnet01.cts.com (personal)
My opinions are my own, and do not represent those of my employer.
My interaction with our news system is unstable; please mail anything important.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads