No, that’s not misspelled (at least not by me). In looking for subjects for my next homework project, I opened our shed and found something I thought would be interesting: This is an old style pachinko (パチンコ) machine. In fact, this is the infamous “King Gorira” machine, with a King Kong type theme for the centerpiece:

The user flips a lever and a little steel ball is shot to the top of the play area. The ball bounces around the pins and a prize is awarded based on where the ball lands. The prize is, of course, more little steel balls. Since these machines were (and are) used for gambling similar to the way slot machines work in U.S casinos, I guess you could say that a gambling addiction with this machine would be like having a monkey on your back. You could say that; I wouldn’t because it’s insensitive. What struck me as interesting about it is that it is a *physical* machine. There are no electronics used in getting it to work, but work it does. Well, my model doesn’t work (that’s why it’s in the shed), but this type of machine can and does work well. This class is still about computational thinking and seeing computer concepts in everyday life. So what does this machine compute?

The machine is like a black box function. Well, specifically it IS a box, and it ACTS LIKE a function. One little steel ball goes in, and zero or more little steel balls come out. But what function is being represented? It is a gambling machine, so it is a safe bet (har, har) that it is a random function (a function that returns a random result). Common sense tells us that the random function is probably biased towards no little steel balls coming out (loss) rather than many little steel balls coming out (win). The following questions are now posed:

- Where is the mechanical source of randomness?
- Is the bias an adjustable property?
- How can this functionality be modeled and/or manufactured?
- How can the randomness be interpreted?

Common sense tells us that if you do the same action twice, you get the same result twice. This is true on a large scale. If you let go of a glass tumbler over a cement floor, the glass will drop and break. Every time. Action: drop, Result: break. Take my word for it. If on the other hand we look at the details, things change. The glass does not always break into the same number of pieces, nor are the pieces always the same shape. A coin is another example. In the big picture, I can spin a coin on a table, and every time it will spin for a while and then come to a stop flat on the table.^{[1]} In detail, each time it will either land on heads or tails:

The truth is this: *you can’t really do it the same way every time*! Every time you spin a coin (or drop a glass, or whatever) you do it a little bit differently. The torque applied to the coin, the starting position of the glass, the air density under the wings of a butterfly. There are all sorts of little variations that add up. This is called *chaos*, which is a Greek word meaning “I don’t know what comes next”. In the case of the pachinko machine, the little steel ball changes direction every time it hits a pin. The direction it travels (other than a simple “down”) is dependent on the angle of impact as well as the speed, direction, and rotation of the ball. Even minute changes in any of these things could effect the change of direction. Also every time a pin is hit, the velocity and rotation of the little steel ball changes as well. So by hitting a series of pins, the machine is not *creating* randomness, as much as it is *making use* of the chaos that is inherent in nature.

Since the bias of the result is built into the positioning of the pins and the placement of the “reward” centers, I believe that the bias could be changed (or eliminated) by changing the position of the pins. To eliminate the bias, the little steel ball would have to start with (approximately) the same position and velocity every time and the pattern of pins would have to be regular. Specifically, if the little steel ball hits a pin from the top, it has two options: *bounce right*, or *bounce left*. Putting a pin under each of these options, would cause an additional choice of the same type. Putting a pin under each of these options and continuing the pattern would yield a “more random” answer in the same sense that flipping a coin multiple times would provide a larger set of potential random results (one flip: {heads, tails}, two flips: {heads/heads, heads/tails, tails/heads, tails/tails}).

This gives us options as to implementation of the best pin pattern. To achieve unbiased random results, I would think a fixed pattern of pins with offset alternating rows would work:

However, if we are dropping the little steel ball from the same spot every time, only the pins inside the green triangle are needed:

Given a single start point and two possible options each time a ball hits a pin, we get a finite state machine that looks something like this:

In the diagram, each state is labeled with the paths a little steel ball could take to get to that state. The output of our mechanical function is the position of the little steel ball as it leaves the grid of pins, represented by the end states in the graph. Since, for our purposes, the output of a random function (mechanical or otherwise) needs to be a random number, the output could be interpreted in a number of ways. The most straight forward is that there are six different ways that the little steel ball can leave the pins, so the output of our randomness “function” is a random number between 0 and 5, inclusive. Things to note at this point:

- We are assuming (and reasonably so) that the chance of a little steel ball bouncing left/right is 50%/50%.
- We are are then assuming (based on assumption 1) that all paths through the pins are equally likely.
- If the output positions are numbered 0 through 5, a little steel ball is more likely to end up as a 2 or a 3 than as a 0 or a 5.

This means that our random numbers would not be unbiased. To get unbiased random numbers (or more accurately to control the bias of the numbers) I believe the best method would be to find the probability of each output position occurring and then map the output positions to either 0 or 1 based on this data. This would allow the bias of a 0 or 1 (win/loss) to be shifted accordingly. To arrange for no bias, using an odd number of rows of pins (which means an even number of output states) and alternating the output stats mapping between 0 and 1 would work, because each result (0,1) in aggregate would have the same number of paths leading to it. Thus, the result of dropping multiple little steel balls would be to generate a random string of 0’s and 1’s which would allow for random numbers of any size or range.

^{[1]} Actually, there was one time it didn’t, but that time there was a Ouija board, a dyslexic chinchilla, and a jar of mayonnaise substitute involved, so I don’t give it much credit.