## Saturday, January 22, 2022

### 275: Demanding Fair Dice

Welcome to Math Mutation, the podcast where we discuss fun, interesting, or weird corners of mathematics that you would not have heard in school.   Recording from our headquarters in the suburbs of Wichita, Kansas, this is Erik Seligman, your host.  And now, on to the math.

Recently I was amused to hear about a strange machine called the “dice-o-matic”, a monstrous 7-foot tall machine that can physically roll thousands of dice per day.   It uses a camera to automatically capture the results and serve them up on the internet, for players of online board and role-playing games who need trustworthy rolls of virtual dice.   This was created by the hosts of the website gamesbyemail.com, as a result of demands by players for real dice rolls to apply to their games.    At first I thought this was rather silly— after all, nearly every programming language these days offers an option to generate a random number, so why would someone need physical dice rolls?   But as I read more about it, I could sort of understand the motivation.

To start with, let’s review how most random numbers are generated on a computer.   Typically these are not truly random numbers, but pseudo-random:   each number is derived from the previous one, but in such a way that they would effectively appear random to an external observer not aware of the algorithm used.    For a given “seed”, or starting number, they will always generate the same sequence.   The most common algorithm for such numbers is the Linear Congruential number generator.   For example, suppose you are trying to generate a random number between 0 and 7.   A simple Linear Congruential generator might take the current number, multiply it by 5, add 1, and then calculate the remainder modulo 8.   If we start with the number 0, we get the sequence 0,1,6,7,4,5,2,3, a pretty random-looking sequence of 8 numbers.    That sequence would then repeat forever— this type of generator naturally has that property.   But in real life, the numbers used for the multiplication, addition, and modulo operators would be much higher, so the cyclic nature would almost never be exposed.   By the way, the deterministic nature of these pseudo-random numbers can actually be beneficial in many applications:  for example, if testing a microprocessor design with random simulations, knowing the seed that led to discovering a malfunction enables you to easily repeat the exact same random test.

Usually you would try to get some number from a random physical source to set the seed, so you would not have the same sequence of numbers every time.  On unix systems, the /dev/random file looks for environmental noise, such as device driver delays, for storage in an “entropy pool” of random starting seeds.   There are other even better methods:  quantum physics supplies true randomness, through the timing of radioactive decays, for example.   And there are silly-sounding methods online that can be quite effective, such as the program at lavarand.org for generating random values using patterns observed in lava lamps.    Various online services provide true random numbers generated through other methods.    Of course, if you can generate these seeds with true randomness, you might argue that you should generate all your random numbers this way instead of using a pseudo-random algorithm.  But remember that current microprocessors run blazingly fast, with billions of operations per second.   Anything requiring input from the external world is going to create extra delays that are huge compared to internal operations.    So it’s much more common to use these true random sources just for the seed.

Which brings us back to the motivation for the dice-o-matic.   According to the description on their website, users were dissatisfied with the randomness of their earlier pseudo-random method.   They write:  “Some players have put more effort into statistical analysis of the rolls than they put into their doctoral dissertation.”   Personally, I’m a bit skeptical—   in any set of random numbers, you are going to see streaks of values that appear non-random.   There may be a run of 20 low numbers in a row, or an ascending 1-2-3-4-5-6 in a few places, etc.    I bet most of the complaining users had lost a game or had their D&D characters killed due to bad rolls that appeared in such a sequence, and were looking for external causes to blame.   On the other hand, if they put in enough effort, it should often be possible to demonstrate the non-randomness of pseudo-random numbers.   The website random.org points out some applications, such as scientific simulation of virus infections, where this lack of randomness has had detectable effects.  In any case, the gamesbyemail.com people took the issue seriously, and the dice-o-matic was their solution, freeing them from the dangers of pseudo-randomness.

We should also keep in mind, however, that dice actually aren’t the greatest sources of true random numbers either:   wear and tear will cause them to regularly depart from true randomness over time, as well as other possible issues depending on the manufacturing process, like the different amounts of material cut out to make the pips on each side.    Personally, I think the gamesbyemail people might have been better off installing a few number-generating lava lamps.

And this has been your math mutation for today.

References: