home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!flu!lowry
- From: lowry@watson.ibm.com (Andy Lowry)
- Subject: Re: FULL HOUSE (REVISED)
- Sender: news@watson.ibm.com (NNTP News Poster)
- Message-ID: <LOWRY.92Sep14133846@rotor.watson.ibm.com>
- In-Reply-To: ppc1@cec1.wustl.edu's message of Sun, 13 Sep 1992 22:31:47 GMT
- Date: Mon, 14 Sep 1992 18:38:46 GMT
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- References: <1992Sep13.223147.28768@wuecl.wustl.edu>
- Nntp-Posting-Host: rotor.watson.ibm.com
- Organization: IBM T.J. Watson Research Center
- Lines: 27
-
- In article <1992Sep13.223147.28768@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...
-
- > 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);
- > }
-
- Try again. Trace through an execution of getRandom when you've
- already dealt out {10,34,18} and then getRandom tries to deal 34
- again. Surprise! It succeeds in doing so. It turns out the only
- case you've avoided with your fix is dealing the same second card as
- first card.
-
- --
- Andy Lowry, lowry@watson.ibm.com, (914) 784-7925
- IBM Research, P.O. Box 704, Yorktown Heights, NY 10598
-