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 Marsalis’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).
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 Random Gaussian that prints a random number r drawn from the Gaussian distribution. One way to do so is to use the Box–Muller formula
where u and v are real numbers between 0 and 1 generated by the Math. random() method.
Solution. Since both 10 and 3 are integer literals, Java sees no need for type conversion and uses integer division. You should write 10.0/3.0 if you mean the numbers to be double literals. If y
Program 2.2.2
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here