Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ut-sally.UUCP Path: utzoo!linus!philabs!seismo!ut-sally!riddle From: riddle@ut-sally.UUCP (Prentiss Riddle) Newsgroups: net.games.rogue Subject: Re: Nonexistent patterns in random numbers Message-ID: <627@ut-sally.UUCP> Date: Wed, 14-Dec-83 16:22:47 EST Article-I.D.: ut-sally.627 Posted: Wed Dec 14 16:22:47 1983 Date-Received: Fri, 16-Dec-83 02:38:12 EST References: <461@seismo.UUCP> Organization: U. Texas CS Dept., Austin, Texas Lines: 150 Not only do people insist on seeing patterns in random numbers, but the converse is also true: when people try to create a sequence of random numbers, they usually insist on building patterns into it. Years ago, the magazine "Creative Computing" published a rather simple- minded program to demonstrate this. It asked the user to pretend that s/he was repeatedly flipping a coin. The program would try to antici- pate each "h" or "t" entered by the user. The number of correct guesses was expressed as a percentage; with a large number of guesses, the score would almost always stabilize well above 50%. For what it's worth, here is my re-creation of that "Creative Computing" program. If you work at it, it's quite easy to outwit the program, but if you stick with the premise that it's trying to test (i.e., just imagine that you're flipping a coin), you'll probably find that your flips are anything but random. -------------------------------------------------------------------------- /* guess - heads/tails guesser 12/14/83 * * Guess is intended to demonstrate that human beings are poor random * number generators. The model for this program appeared in an old * (ca. 1975?) issue of "Creative Computing". * * Compilation: "cc -o guess guess.c" * * Author: Prentiss Riddle (...{ihnp4,seismo,ctvax}!ut-sally!riddle) */ #include #define CBREAKON "stty cbreak" /* system command to turn on cbreak mode */ #define CBREAKOFF "stty -cbreak" /* system command to turn off cbreak mode */ #define HEADS 1 #define TAILS 0 main () { int flipit(); /* flip a coin */ int quit(); /* exit routine */ static int history[2][2][2] = {{{0,0},{0,0}},{{0,0},{0,0}}}; /* history -- three flips of heads/tails */ int f1, f2, f3; /* three flips determining current state */ int flip; /* user's flip */ int guess; /* computer's guess */ int fcount = 0; /* flip count */ int score = 0; /* flips correctly guessed by computer */ char c; /* user input */ long seed; /* seed for random number generator */ /* set up interrupt handling and cbreak mode */ signal (SIGINT, quit); system (CBREAKON); /* randomize initial state */ seed = getpid() + 1984; f1 = flipit(&seed); f2 = flipit(&seed); f3 = flipit(&seed); while (1) { /* perform guess */ if (history[f1][f2][f3] > 0) guess = HEADS; else if (history[f1][f2][f3] < 0) guess = TAILS; else guess = flipit(&seed); /* read user's flip */ do { printf ("h(eads),t(ails),q(uit):"); c = getchar(); switch (c) { case 'h': flip = HEADS; break; case 't': flip = TAILS; break; case 'q': case '\0': /* control D */ putchar('\n'); quit(); break; default: putchar('\n'); flip = -1; break; } } while (flip == -1); /* update score */ ++fcount; if (flip == guess) ++score; /* update history */ switch (flip) { case HEADS: ++history[f1][f2][f3]; break; case TAILS: --history[f1][f2][f3]; break; } f1 = f2; f2 = f3; f3 = flip; printf (" my guess:%c my score: %d out of %d (%2d%%)\n", ((guess == HEADS) ? 'h' : 't'), score, fcount, (int) (((float) score / (float) fcount) * 100.0 + 0.5) ); } } int flipit (seed) /* flip a coin */ /* random number generator taken from Grogono p. 119 */ long *seed; /* seed for random number generation */ { *seed = ( 25173 * *seed + 13849 ) % 65536; return (((((double) *seed) / 65536) > 0.5) ? HEADS : TAILS) ; } quit () /* fix terminal back up and exit */ { /* turn off further interrupts */ signal (SIGINT, SIG_IGN); /* turn off cbreak mode */ system (CBREAKOFF); /* bye-bye */ putchar ('\n'); exit (0); } -------------------------------------------------------------------------- Prentiss Riddle {ihnp4,seismo,ctvax}!ut-sally!riddle