Makerspace - Random Dice Roller

 1. Project:

In this week’s challenge, our goal was to learn use the random function, custom embedded functions, for loops and if statements to create a random dice roll and then count the distribution of dice rolls.

2. Code:

The following code displays a random dice roll on a 7-LED array and counts the distribution of rolls for 100 dice rolls.





3. Circuit Design:

For the following circuit design, the 7 LED's are arranged so a to display the typical dice number arrangements from 1 through 6 for each random number that is generated.


Video of Circuit for Random Dice Roller (0:25)

4. Electronic Diagram:

The following electronic diagrams were taken from my design journal.

For the following circuit design, the potentiometer functions as a color selector. Turning the knob on the potentiometer will determine which color the RGB LED will shine.



Electronic Diagram for Random Dice Roller

5. Video of Project:



Description of Project to Create Random Dice Roller (2:52)

6. Explanation of Project:

I started this week by learning how to use the random() function to generate the integers 1 through 6. I initially plugged in 6 as the "max". However, using the serial.print output, I was able to quickly discover that this only generated numbers 1 through 5 and corrected my mistake by changing the "max" to 7. This correctly generated the random numbers I wanted.

Next, I wrote a function to take the random dice number and display it on my 7-LED arrangement. This took a little troubleshooting on the syntax of my if statements, but it looked really cool once it started working!

Finally, I automated the counting process to track how many times I rolled a 1, 2, 3, 4, 5 or 6 in 100 rolls. I then displayed that using the serial.print function so that I could graph it when I was done!

7. Reflection:

This week was a lot of trial and error. I decided to challenge myself by starting my code completely from scratch without any references or guides. I was able to learn more about how integer variables work, how to use for and while loops, and how to use embedded functions to reduce the amount of repetitive coding I would need to do. It think this will help me be more efficient in the future. 

8. Applications:

A very obvious application for this would be the computerized slot machines at casinos. It makes you wonder how fair these machines actually are, and what random seeds they use as their input to their random functions. I'm sure someone monitors their code... I would hope! But it seems like a giant loophole for casinos to make more money!

9. Graph of Dice Roller Distribution

Below is the graph of my dice roller number distribution for 100 rolls. 

Comments

Popular posts from this blog

Web 2.0: Continuing the Journey

Online Learning: Course Management Systems

Playtesting Assignment 1: Blogs