Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3dc9c45

Browse files
committed
Add context for prep exercise
1 parent 955d596 commit 3dc9c45

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Week3/prep-exercises/2-experiments/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Let's do some experiments! One thing computers are great at is doing the same thing over and over and over again, so let's use that to see how random the random function in JavaScript is. In the `index.js` there is an explanation of what to implement. In essence we want to simulate the rolling of a die a lot of times and then track how many times a certain value was rolled.
44

5+
For a fair die the chance of rolling a certain value should be equal for all possible values. When rolling a six-sided die many times we therefore expect the number of times each value is thrown to approach 16.6% (1/6) of the total number of rolls. The more rolls we do the closer we should get to the expected value, following the [Law of large numbers](https://en.wikipedia.org/wiki/Law_of_large_numbers).
6+
7+
> Wikipedia: _In probability theory, the law of large numbers (LLN) is a theorem that describes the result of performing the same experiment a large number of times. According to the law, the average of the results obtained from a large number of trials should be close to the expected value and tends to become closer to the expected value as more trials are performed._
8+
9+
In this prep exercise we are using the `Math.random()` function to simulate throwing a die. So what we are actually testing here is how well `Math.random()` distributes its values evenly across the range of 0 to 1 when called many times. We will do this for an increasing number of rolls (`sampleSize` in the code) and expect the results to even out to 16.6% across all values.
10+
511
## Things to think about
612

713
- The `valueCounts` is implemented as an array. Do you think there is another way to store this? Why do you think the decision was made to go with an array?

0 commit comments

Comments
 (0)