# lab6 - CS100M Lab Exercise 6 1 Roll a fair die Write a...

• Lab Report
• 2

This preview shows pages 1–2. Sign up to view the full content.

CS100M Lab Exercise 6 1 Roll a fair die Write a function rollDie(n) to simulate the rolling of one six-sided die n times. The function draws a histogram of the result. Below is an example histogram. Use a vector to count the number of times that each face occurs. 1 2 3 4 5 6 0 0.5 1 1.5 2 2.5 3 10 rolls of a fair die Outcome Count For example, use a vector count with six cells such that count(f) is the number of times that face f has occured. Solve this problem without using an if statement. You will need to generate random integers in [1..6]. You can use a built-in function to create a row (vector) of six zeros: zeros(1,6) . Use the built-in function bar to draw a bar graph: bar(1:6, count) where the first argument (1:6) contains the labels for the bars and the second argument ( count ) contains the counts for the six possible outcomes. Label the axes and the figure. 2 Roll multiple dice Write a function rollDice(n,d) to simulate the rolling of d six-sided dice n times. We define the outcome of rolling d dice once to be the sum of the faces that show up. In the function, create a vector

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Summer '07
• FAN/VANLOAN
• Dice, built-in function

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern