Problem

Gaussian random values. Implement the no-argument gaussian() function in StdRandom (PROGRA...

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-whi 1 e at the end of SECTION 1.3).

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

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

EXERCISE 1.2.27

Gaussian random numbers. Write a program RandomGaussian that prints a random number r drawn from the Gaussian distribution. One way to do so is to use the Box–Muller formula

r = sin(2 πv) (−2 ln u)1/2

where u and v are real numbers between 0 and 1 generated by the Math.random () method.

Program 2.2.1 Random number library

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2.2