applets.

Random or Not?

← All apps

About Random or Not?

Three ways into one question: what does random really look like?

BE RANDOM. Be the coin: press HEADS or TAILS (or the H and T keys) 100 or 200 times, as randomly as you can. Before each one, the book seals its guess at what you'll press next, and the little red dots show where it was right. When the table is full it compares your string with a fair coin: how often you switched, your longest run, how many runs of each length (against the Expected number), and how well it guessed you, then stamps it looks human or looks random, with its reasons. Backspace takes one back. TOSS REAL COINS fills a table from the computer's own random numbers, to see what the real thing looks like (now and then even a real coin gets called human: that's chance).

SPOT THE FAKE. Two tables of 100 tosses: one tossed for real, one written the way people write them. Pick the real one (click it, or press A or B; N for the next pair). The faker can be clumsy, typical or sly.

THE TESTS. Five ways of making random numbers on a computer, and five simple tests of them. Pick one, choose how many numbers, press RUN. The plate shows each number against the next (pairs) or three in a row as a cube you can turn (triples): drag it, or use the arrow keys.

THE STORY

Ask a class to write down 100 coin tosses and they'll switch from heads to tails too often and avoid long runs, because six heads in a row feels wrong. A real coin switches about half the time and in 100 tosses has a run of six or more about 80% of the time. That's the old classroom trick: half the class tosses a coin, half makes it up, and the teacher picks out the fakes at a glance by looking for the long runs. People make poor random generators in other ways too, and a program that only remembers what you did after your last few presses can usually guess your next one better than chance.

Computers can't toss coins either. Early on, scientists used printed tables: in 1927 Leonard Tippett published 41,600 digits taken from census figures, and in 1955 the RAND Corporation published A Million Random Digits with 100,000 Normal Deviates, made by an electronic roulette wheel: a book of nothing but random numbers, still in print. Faster is to calculate them: in 1949 John von Neumann suggested the middle-square method (square a number and keep its middle digits), knowing it soon falls into a loop; he wrote that "anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." The same year Derrick Lehmer proposed multiplying by a constant and keeping the remainder; with an addition as well, that's the linear congruential generator, still found everywhere. Its most famous failure is RANDU, supplied with the scientific subroutines of 1960s mainframes and widely used: it passes simple tests, but every three numbers in a row lie on one of just 15 flat planes in a cube, and results from that era that relied on it are still treated with suspicion.

HOW IT WORKS

The guesser remembers, for each of your last one to five tosses, what you pressed next every time before, and bets on the more common answer, trusting whichever length of memory has been right most often so far. With nothing to go on it bets you'll switch. It writes each bet down before you press.

The verdict uses exact odds for a fair coin: the number of switches in n tosses is like n − 1 coin tosses of its own (Expected (n − 1) ÷ 2); the chance of the longest run being a given length comes from counting every possible string; the Expected number of runs of length k is (n − k − 1) ÷ 2k+1 + 2 ÷ 2k. A string is flagged if it is in the outer 1% on switches, longest run or heads, or if the guesser did better than a blind guesser would 99 times in 100. The typical faker in SPOT THE FAKE switches about 60% of the time, never lets a run pass five, and evens up heads and tails when one side gets ahead.

The tests turn each number into a toss (under ½ is heads) or into a digit 0–9: frequency counts each tenth (chi-squared), coin balance the heads, switches and longest run as above, pairs the 100 combinations of two digits side by side (chi-squared). A test fails when the result would happen less than 1 time in 1,000, so even a good generator fails one now and then; a chi-squared result that is too good to be true is stamped too even. Real test suites run hundreds of much harder tests than these.

The Python scripts Random Symbol Generator.py and Random Symbol Generator v2.py this app grew from shuffle a line of symbols by pulling them out at random, one at a time.

FURTHER WATCHING AND READING

Random or Not? Tables & Tests
Table I. Your tosses2

Be the coin. Press heads or tails as randomly as you can. Before each press the book seals its guess.

 
Tosses
the book guessed it your longest run Keys H T, Backspace takes one back
Table I. Compared with a fair coin3
 YouA fair coin
Heads0
Switches0
Longest run0
The book's guesses0 of 0half right, by chance

Plate 1. Runs of each length: yours (black) against the Expected number for a fair coin (red).