Question: Gaussian random values. Implement the no-argument gaussian() function in StdRandom (Program 2.2.1) using the Box-Muller formula (see ExerCISE 1.2.27). Next, consider an alternative approach, known

Gaussian random values. Implement the no-argument gaussian() function in StdRandom (Program 2.2.1) using the Box-Muller formula (see ExerCISE 1.2.27). Next, consider an alternative approach, known as Marsaglia's method, which is based on generating a random point in the unit circle and using a form of the Box-Muller formula (see the discussion of do-while at the end of Section 1.3).

public static double gaussian () { double r, x, y%;B do }

For each approach, generate 10 million random values from the Gaussian distribution, and measure which is faster.

public static double gaussian () { double r, x, y%;B do } { x = uniform (-1.0, 1.0); y = uniform (-1.0, 1.0); rx*x+yy; } while (r = 1 || r 0); return x * Math.sqrt(-2 * Math.log(r) / r);

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 Algorithm Design Questions!