Question: Suppose we toss darts randomly at a square dartboard, whose bullseye is at the origin, and whose sides are 2 feet in length. Suppose also

Suppose we toss darts randomly at a square dartboard, whose bullseye is at the origin, and whose sides are 2 feet in length. Suppose also that theres a circle inscribed in the square dartboard. The radius of the circle is 1 foot, and its area is square feet. If the points that are hit by the darts are uniformly distributed (and we always hit the square), then the number of darts that hit inside the circle should approximately satisfy the equation. (number in circle total)/(number of toss) = /4, since the ratio of the area of the circle to the area of the square is /4. We can use this formula to estimate the value of with a random number generator:

float pi_estimate = 0.0;

int number_in_circle = 0;

for (toss = 0; toss < number_of_tosses; toss++)

{

x = rand_range(-1, 1);

y = rand_range(-1, 1);

distance_squared = x*x + y*y;

if (distance_squared <= 1) number_in_circle++;

}

pi_estimate = 4*number_in_circle/((float) number_of_tosses);

This is called a Monte Carlo method, since it uses randomness (the dart tosses). Write a MIPS program that uses a Monte Carlo method to estimate . The program iterates the total number of tosses and prints out the result. Run your program while varying the number of tosses, 100, 1,000, 10,000, to obtain reasonable estimate of .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!