home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / programm / 2603 < prev    next >
Encoding:
Text File  |  1992-09-14  |  1.4 KB  |  42 lines

  1. Newsgroups: comp.programming
  2. Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!flu!lowry
  3. From: lowry@watson.ibm.com (Andy Lowry)
  4. Subject: Re: FULL HOUSE (REVISED)
  5. Sender: news@watson.ibm.com (NNTP News Poster)
  6. Message-ID: <LOWRY.92Sep14133846@rotor.watson.ibm.com>
  7. In-Reply-To: ppc1@cec1.wustl.edu's message of Sun, 13 Sep 1992 22:31:47 GMT
  8. Date: Mon, 14 Sep 1992 18:38:46 GMT
  9. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  10. References: <1992Sep13.223147.28768@wuecl.wustl.edu>
  11. Nntp-Posting-Host: rotor.watson.ibm.com
  12. Organization: IBM T.J. Watson Research Center
  13. Lines: 27
  14.  
  15. In article <1992Sep13.223147.28768@wuecl.wustl.edu> ppc1@cec1.wustl.edu (Peter Pui Tak Chiu) writes:
  16.  > // this previous version of this program assumes that we are drawing from
  17.  > // an infinite deck.  (which is a bug).
  18.  > 
  19.  > // now this version has no such problem...
  20.  
  21.  > int getRandom(){
  22.  > int n,BAD=1;
  23.  > while(BAD){
  24.  > n=rand()%52+1;
  25.  > for(int i=0;i<5;i++){
  26.  >     int FLAG=0;
  27.  >     if(n==hand[i])FLAG=1;
  28.  >     if(!FLAG)BAD=0;
  29.  >     }}
  30.  > return(n);
  31.  > }
  32.  
  33. Try again.  Trace through an execution of getRandom when you've
  34. already dealt out {10,34,18} and then getRandom tries to deal 34
  35. again.  Surprise!  It succeeds in doing so.  It turns out the only
  36. case you've avoided with your fix is dealing the same second card as
  37. first card.
  38.  
  39. --
  40. Andy Lowry, lowry@watson.ibm.com, (914) 784-7925
  41. IBM Research, P.O. Box 704, Yorktown Heights, NY  10598
  42.