Automatic Die Tester

Good randomness is important, so I built a die tester: A stepper controlled by an Arduino spins a transparent box containing the die I want to test, a camera takes a picture that is transferred to my PC, and a python script uses openCV to determine the side of the die that faces the camera.

The box was made using BoxMaker and the local FabLab’s laser cutter and then connected to the stepper motor using a little 3D-printed plastic cross thingy (and lots of duct tape).

The biggest problem by far during this project was that sometimes the box would not return to its home position and instead be skewed by a few degrees, which tended to get worse over time. This usually seemed to happen after the motor had been running for a while, and got worse when I attached it to the table more tightly - I suppose it was just caused by the motor not being able to produce enough torque to start or stop the box.

The source code is on GitHub, if you want to play with it. It’s a bit of a mess and needs to be changed when the light conditions change, or if you want to switch between dice with pips and dice with numbered faces, but it works for now - and if you need help with it, feel free to contact me.

Results with a random die from my dice bag

After 559 rolls the 3D-printed thing fell apart, so I stopped the experiment. Mean and standard deviation of the die are 3.47±1.74 (expected: 3.5±1.71 ([Wikipedia on uniform distributions] (

A chi-squared test on the [resulting distribution (log of each number)] (/project-files/automatic-die-tester-d6-green-rolls.txt) gives us a probability of 92% that this is a fair die. This is not particularly stellar, but could be worse, as you’ll see in just a bit.

At an initial glance there seemed to be a bias towards getting the same roll twice, which I attributed to bad rolling. Another chi-squared test comparing each combination’s probability with the multiplied probabilites of each number of the pair told me that the rolling worked well, however (p=1.0).


I want to test a die’s properties before and after being subjected to a little melting in an oven and see how much it’s affected by, I don’t know, 5 minutes or so at 100°C.

Die before any modifications, after 500 rolls

Results are here

Mean: 2.402, std. dev.: 1.774, chi-squared: 0.198

Let’s hope that this is indeed a tremendously bad die and that I did not simply get unlucky. 1 is a lot more frequent here, with 103 rolls instead of the expected 83.

After 2.5 minutes in the oven, at 100°C

I put the die in the oven at 100°C for approx. 2.5 minutes, with the 6 on the bottom, which is the side I take my pictures from. This means that the frequency of 6 should increase, and the frequency of 1 decrease.

Results are here

Mean: 2.470, std. dev.: 1.703, chi-squared: 0.727

The 1 only occurs 88 times in this experiment. Mean and standard deviation are much closer to the expected values, and the chi-squared test confirms that the die is much fairer now. Maybe this is actually a somewhat reasonable way to improve the quality of bad dice?

After another 2.5 minutes in the oven

Results are here

Mean: 2.543, std. dev.: 1.650, chi-squared: 0.522

As was to be expected, the mean’s gone up a little more, once again by about 0.07. The die’s quality as measured by the chi-squared test has become a little worse again. There’s not much more to be said (that I can think of), except that a visual inspection of the die does not reveal any unevenness. You can take my word for it, or take a look for yourself with the [images] (#images) I’ve taken.