{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# a08f4 - CS1MD3 08F4.1 Assignment 4 Due Nov 25(Tuesday 23:59...

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

CS1MD3 08F4. 1 Assignment 4 Due . Nov. 25 (Tuesday), 23:59. In this assignment, write all documents in javadoc style. 1. Although it is often easier to think of random numbers in the context of games of chance, they have other, more practical uses in computer science and mathematics. For example, you can use random numbers to generate a rough approximation of the constant π by writing a simple program that simulates a dart board. Imagine that you have a dart board hanging on your wall. It consists of a circle painted on a square backdrop. If you throw darts at this board in a random fashion, some will fall inside the circle. If the tosses are truly random, the ratio of the number of darts that land inside the circle to the total number of darts falling anywhere inside the square should be roughly equal to the ratio between the two areas. The ratio of the areas is independent of the actual size of the dart board, as illustrated by the following formula: darts falling inside the circle darts falling inside the square area of the circle area of the square = πr 2 4 r 2 = π 4 . To simulate this process in a program, imagine that the dart board is drawn in the standard Cartesian coordinate plane you learned about in high school. You can model the process of throwing a dart randomly at the square by generating two random floating-point numbers x and y , each of which lies between - 1 and 1. This ( x, y ) point always lies somewhere inside the square. The point ( x, y ) lies inside the circle if

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ 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