My dice rolls aren’t random!

I’ve received a lot of feedback lately regarding the dice in Uckers. Sometimes it’s a feeling that too many 6s appear in a row or dare I say it, the computer is just a six throwing b******d!

So let me dispel any myths here for you. All the dice rolls are random. I’ll say that again, all the dice rolls are random. There’s no way the computer player can influence the dice or see ahead what dice it will roll in the future. Uckers uses an industry standard pseudo-random number generator called “arc4random” which was used for a long time as a cryptographic random source (the gold standard for random number generation). As it was cracked a while ago, it’s use is now confined to non-cryptographic applications – like Uckers.

Hold on a minute, I said pseudo-random so it’s not really random? Random number generation is a huge topic so I won’t go into anymore detail here. Suffice to say that if the number is random enough for huge cryptographic data streams, it’s random enough for a dice roll. According to Wikipedia a pseudo-random number does not rely on sources of naturally occurring entropy where a true random number generator does.

In the interest of full disclosure, the first version of the app used an implementation of the function that introduced something called ‘modulo bias’. This is corrected in subsequent versions but if anything would have resulted in a tiny increase in the number of 1s rolled. In practice though you’d need to make millions of rolls to notice this.

So why does the computer keep rolling a 6?

A good question. It turns out that humans are actually not that good at assessing randomness.

A closer look at the computational problem people face suggests that judgments about randomness are inherently difficult, even with optimal statistical knowledge and extensive computational resources, and errors in judging randomness may reflect the difficulty of the problem rather than misleading intuitions about chance events.

Why are people bad at detecting randomness

Humans typically try to find patterns in random data, perhaps more so when a reward is associated (rolling a 6). Do you know how many times you have rolled six 2s in a row? Probably not but if you’re going to assess how random it is to get six 6s in a row then you’d be interested in the same information for all the other numbers.

It’s also worth noting that getting 3 doubles in a row or 6 sixes is not that common in the real life game of Uckers. In the app however, rolls (and games) can take place much quicker so intuitively it may appear that these seemingly unlikely events are coming up quicker.

What about probability? Sure, understanding the probability of dice rolls would help us assess how random these events appear to be. So for a 2 dice roll, the probability of me rolling a six can be calculated as follows:

There are 36 possible combinations of a 2 dice roll (6^2). The probability of rolling a double six from one roll is therefore 1/36 or 0.0278.

Combinations involving a single six but not a double 6 are: 6,1; 6,2; 6,3; 6,4; 6,5; and 1,6 2,6; 3,7; 4,6; 5,6. Ie. 10 in 36 or 0.2778.

So on a 2 dice roll, there is roughly a 28% chance one of them will be a six and a 2.8% chance it will be a double six.

Next to calculate the chance of 6 sixes in a row, we need to consider how this can be achieved. You could:

  1. Roll a single six 6 times
  2. Roll a double six 3 times
  3. Roll a double six and 4 single sixes (there are 5 total variations of this): DSSSS, SDSSS, SSDSS, SSSDS, SSSSD
  4. Roll 2 double sixes and 2 single sixes (6 total variations of this): DDSS, DSDS, DSSD, SDDS, SDSD, SSDD

So there are 13 ways 6 sixes in a row can be achieved. The probability is the addition of each of the 13. So to calculate and sum each of the above points:

  1. (10/36)^6 = 0.0004594
  2. (1/36)^3 = 0.0000214
  3. 5* 1/36 * (10/36)^4 = 5 * 0.0277778 * 0.0059537 = 0.000827
  4. 6*((1/36)^2 * (10/36)^2) = 6 * 0.0007716 * 0.0771605 = 0.00035722

The sum of points 1-4 is therefore:

0.001665 = 1 in 600

The average game length using entirely random moves is around 150 dice rolls so you would expect to see 6 sixes once per 3 games. Or more, or less, it’s random!

It’s also important not to get confused between a random number and a uniform distribution of numbers. For example, when generating a random dice roll, the code could look at all the dice rolls that have come before and make sure that there are always the same number of 5s as there are 6s as there are 1s etc…

The problem with this method is that you’d never get 6 sixes in a row because the computer would constantly be correcting for any imbalance in the number of sixes and throw in a few other numbers to compensate. Most importantly though, that’s not how dice work.

As an indicator of how the dice behave in the app, on the completion of a game you’ll see the total dice rolls during the game displayed as bars. After 1 game, these might be quite different (because don’t forget it’s random, not uniform). However, after a few games, they should all start to converge to within a few % of each other. Thus you can be sure that although the computer is almost definitely a six throwing b******d, it is doing so randomly.