# Christmas Games: How random are dice?

For the evaluation, we will use two key methods: Circle detection to count the pips on images of dice and hypothesis testing to make a quantitative statement about dice randomness.As statistics are better with large n, some enthusiasts went as far to roll dices 10.000 times to test the fairness of their dice..As I didn’t want to throw dice manually, I decided to build a little automated dice thrower using some LEGO®, an Arduino microcontroller, and a webcam..Essentially the die sits in a chamber on a wheel that rotates so that the die spins around..The Arduino turns the wheel for 1.5s, stops for another 1.5s, then the webcam snaps a picture of the outcome, and the process is repeated..The machine in operation and a timelapse of the mechanism can be seen in the videos below.Dice Rolling Mechanism: An Arduino controls a LEGO® motor, which rotates wheels to rotate the die..A webcam captures the outcome.Dice Rolling Mechanism Close Up Timelapse: The two rounded parts allow the die to flip around randomly.As the wheels only rotate in one direction, I added a little asymmetry in the form of two rounded parts so that die also rotates in the perpendicular axis..I let the machine run for approx 2.5 h to create a dataset of ~ 3000 throws..Feel free to contact me if there is interest for the Arduino code or the wiring.Now let’s get to the analysis part..There are several ways to count the number of pips, i.e., we could use morphological operations mask the up-facing side of the die (it is notably brighter than the background) by applying a binary threshold and selecting its convex hull..The number of pips could then be determined by either counting regions or by merely determining the ratio of black to white pixels..I tried several approaches but ultimately decided to use the HoughCircles function from OpenCV as it required the least amount of code to implement..A general introduction can be found here.. More details