- Reset Game
- Book
- BASIC
-
Dice
Original Resources
Download the original BASIC code. Check out the original page the text below was taken from in the Book.
Instructions From the Book
"Not exactly a game, this program simulates rolling a pair of dice at large number of times and prints out the frequency distribution. You simply input the number of rolls. It is interesting to see how many rolls are necessary to approach theoretical distribution:
2 ----- 1/36 ----- 2.7777 . . . %
3 ----- 2/36 ----- 5.5555 . . . %
4 ----- 3/36 ----- 8.3333 . . . %
Daniel Freidus wrote this program while in teh seventh grade at Harrison Jr-Sr High School, Harrison, New York."
Modifications For This Version
I've modified this one heavily. I've used this in my Discrete Structures class to show students the difference between rolling 2 fair normal six-sided dice vs. chosing a random number between 2 and 12 (two is the smallest number you can get when rolling 2 dice).
This version allows the user to choose how many dice, and how many sides each die has. So if you want, you can check the distribution of 10 twenty-sided dice, or whatever you'd like. The default is 2 six-sided dice with 1000 rolls. So if you choose to just simply click "Roll The Dice" you'll get that distribution.
The original version has a warning in the game play that choosing more than 5000 rolls may lock up the computer. Remember, however, it was written in 1978. Modern computers can handle much larger numbers. I've tested this version using 2 six sided dice with 100 million rolls. It definitely isn't fast, but within about 20 or so seconds, it was done. I've tried 1 billion. After about about 2 minutes, it timed out. I've found that 10 million is the perfect maximum. So I've modified the code to not allow anything larger.
Lastly, I've added a checkbox called "True Dice Roll" that stays defaulted to "checked." You can, however, uncheck it. Leaving it checked will simulate rolling dice, whereas unchecking it will generate a random number between the minimum possible roll and maximum possible roll of the dice you've chosen.
For example, if you chose 5 nine-sided dice and 1 million trials, it would generate a random number between 5 and 45 one million times. See the probability section below for more details.
Technical Stuff
This one is written in PHP and will stay written in PHP. Some of the other projects will be partially or completely converted to JavaScript. However, in this case (i.e., running potentially 10,000,000 rolls), we need the power of a server. Since JavaScript runs in the user's browser, there's no way to know how much processing power with have access to. The last thing I want to do is lock up your browser or, worse, your computer.
More Probability Thoughts
When generating a random number between 2 and 12, the probability of any given number showing up is simply 1 out of 11. Run a test on the program right now. Uncheck the box, enter 10,000,000 in the last field, and click "Roll The Dice." You'll see the results show that each number came up about the exact same number of times. Try it again, but this time, leave the box checked. The results will be Normal Distribution Feel free to read the wiki article linked there. However, the basic idead is this. If you roll two dice, there is only 1 way to a 2, and only one way to get a 12. So the probability of either of those events occuring is 1/36 for each one. Whereas a number like 7 has 6 different ways to occur.
The following ordered pairs, each, represent the roll of dice 1 and 2 respectively(3,4), (4,3), (2,5), (5,2), (6,1), (1,6). Thus the probability of getting a 7 is 6/36. Which is a lot higher than the simple 1/11 that occurs when just choosing a random number between 2 and 12. Now that I've sucked the fun out of life . . .
Enjoy Dice!