Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

John Ferguson Lab 2 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#John Ferguson 2/5/15
##Dice Rolling Lab

>**Question 1:** The probability of rolling a certain number is the number of possbile rolls that can sum to that number divided by the total number of possible rolls. What is the probability of rolling a 7? What is the probability of rolling a 2?

**Answer 1:** The probability of rolling a 7 is a 1/6 chance. The chance of rolling a 2 is a 1/18 chance.

>**Question 2:** Comment on the variation of values among the simulation runs. Is 100 rolls sufficient to determine the relative frequency of all the possible rolls?

**Answer 2:** Everytime we ran our simulation the numbers changed because it was at random. Since it was random I didn't see any consistency. Therefore, I don't believe 100 rolls is sufficient to determine the relative frequency of all the rolls.

>**Quesiton 3:** How did increasing the number of simulations affect the results?

**Answer 3:** Increasing the number of simulations gives us more sufficient results. The results were much close to being consistent for example, for 2 the range was anywhere from .24 to .34 in the ratio which is pretty close.

>**Question 4:** How many rolls per simulation does it take before you can accuarately predict the probability of rolling 7 to 3 significant digits five times in a row? How about for the probability of rolling a 2?

**Answer 4:** The amount of rolls per simulation it takes to accurately predict the probablility of rolling a 7 is about 1000 rolls to get if five times in a row. To roll a 2, its about 5000 rolls to get it five times in a row.
25 changes: 25 additions & 0 deletions src/Histogram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Histogram {
private int[] hist = new int [13];
private int totalRolls = 0;

public void tally(int roll) {
hist[roll] += 1;
totalRolls += 1;
}

public int getCount(int roll) {

return hist[roll];
}

public double getRatio(int roll) {

return hist[roll] / (double)totalRolls;
}

public void print() {
for (int i= 2; i <= 12; i++) {
System.out.println(i + ": " + getCount(i) + " " + getRatio(i));
}
}
}
17 changes: 17 additions & 0 deletions src/SimulationRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class SimulationRunner {
public static void main(String[] args) {
Die d1 = new Die();
Die d2 = new Die();

Histogram hist = new Histogram();

for (int count = 0; count < 5000; count++) {
d1.roll();
d2.roll();

hist.tally(d1.getUpValue() + d2.getUpValue());
}

hist.print();
}
}